Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi ALL,

I need to know how to insert the column values into a table by validating some of the columns which is accepting a bad data.

For e.g., If I have a column called "MobileNo" and some one tries to insert the value that exceeds 10 digits in "MobileNo" field, then how to check for the validation(using IF-ELSE or whatever).

My Query(SP) is here:

VB
INSERT INTO dbo.FTA_ReportFileDumpNew

select A.MobileNo,A.CustomerName,A.Product,A.Suk_Type,A.FTR_Date,A.FTA_Date,
A.Sim_No,A.IMSI_No,A.Retailer_No,A.RetailerName,A.MacMobile_No,A.MacPrimary,
A.MacLocation,A.HUB,A.CombinedZone,A.TM_Name,A.TM_Number,A.RETAILER_SMS_DATE,
A.CUSTOMER_SMS_DATE,A.[TAT/Hrs],A.[TAT/Mins],A.MinuteWiseData,0,@UploadedBy,GETDATE()
FROM dbo.FTA_ReportFileDump A where exists
 (select 1 from FTA_ReportTbView B
 where A.MobileNo = B.MobileNo)




Any help or suggestion greatly appreciable.

Regards,

Raj
Posted
Updated 27-Jan-11 23:52pm
v3

1 solution

Have a read on SQL Check Constraints! Read:
SQL CHECK Constraints[^]
SQL CHECK Constraint - 2[^]

Instead of having any logic in query to handle it, you can have check constraints in place and go ahead smoothly.
Other way would be to handle it in UI itself.
 
Share this answer
 
Comments
Nithin Sundar 28-Jan-11 6:16am    
Good Answer. That's useful! Never thought about it that way. :)
Raj.rcr 28-Jan-11 6:54am    
But I already have some data in FTA_ReportFileDump table. So I cannot add the constraint as we are going to insert the data one by one.. Plzzz give me suggestion Using IF-Else Or Select Case for one or more fields.
Sandeep Mewara 28-Jan-11 8:33am    
Whats the issue in this also. Even by 1-to-1 you can just go ahead. Write a script/code that does this for you, keep it in a try-catch in case it fails and just move ahead keeping a log.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900