Click here to Skip to main content
15,911,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone,

I have the following query:
SQL
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,GETDATE(),'Mobile No. Range is Invalid' from dbo.FTA_ReportFileDump A 
WHERE LEN(A.MobileNo) <> 10


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,GETDATE(),'Sim No. Range is Invalid' from dbo.FTA_ReportFileDump A 
WHERE LEN(A.Sim_No) <> 20


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,GETDATE(),'Customer name should not be blank' from dbo.FTA_ReportFileDump A 
WHERE A.CustomerName IS NULL

----------------
Can any one suggest me how to use the "CASE" for the above query.

Regards,
Raj
Posted
Updated 1-Feb-11 20:30pm
v2
Comments
JF2015 2-Feb-11 2:30am    
Added code formatting.
Raj.rcr 2-Feb-11 2:39am    
I didnt understand ur reply. Can u please elaborate

The following is the sample for using the case statement in select query,

VB
SELECT Product,
CASE
WHEN isnull(A.CustomerName,'') in('') THEN Customer name should not be blank'
WHEN LEN(A.MobileNo) not in (10) THEN 'Mobile No. Range is Invalid'
WHEN   LEN(A.Sim_No) not in (20) THEN 'Sim No. Range is Invalid'
END
from dbo.FTA_ReportFileDump A


Try to implement this for your requirement.

Hope this will help you.....
 
Share this answer
 
Comments
Raj.rcr 2-Feb-11 8:10am    
Thank you very much for perfect answer... I tried implementing the same. Finally, I got the solution. Thanx agn.
CASE can be used in any statement or clause that allows a valid expression. For example, you can use CASE in statements such as SELECT, UPDATE, DELETE and SET, and in clauses such as select_list, IN, WHERE, ORDER BY, and HAVING.

Case is not used in INSERT statement.
 
Share this answer
 
Comments
Raj.rcr 2-Feb-11 4:47am    
But its a stored procedure. I want to use it in select statement only. You can see that below INSERT..

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