Hi
I need help in writing a case script in SQL but I am a beginner so I am doing a lot of cutting an pasteing from existing scripts and changing the variables
I have been trying to get this to work for awhile but being unsuccessful so far.
SELECT OMCOMP, AccountFrom =
CASE
when OMCOMP = 'SG1' and OMDIM1 = 1000 or OMCUST = (SELECT Account FROM Finance.dbo.tes tAccount WHERE Country = 'SG1' THEN '1')
when OMCOMP = 'SG1' and OMDIM1 = 1234 or OMCUST = (SELECT Account FROM Finance.dbo.tes tAccount WHERE Country = 'SG1' THEN '2')
ELSE 'OTHERS'
END
FROM Finance.dbo.tes tFMOSAL
Basically I want to create a table that would show 'AccountFrom' either in '1' or '2' or ' Others'
In the first instance, if OMCOMP is 'SG1' and OMDIM1 is 1000 or if OMCOMP is 'SG1' and OMCUST is equal to a number in another table where country is SG1 then Accountfrom will be equal to 1
Thanks very much in advance for any expertise anyone can offer on my issue.
I need help in writing a case script in SQL but I am a beginner so I am doing a lot of cutting an pasteing from existing scripts and changing the variables
I have been trying to get this to work for awhile but being unsuccessful so far.
SELECT OMCOMP, AccountFrom =
CASE
when OMCOMP = 'SG1' and OMDIM1 = 1000 or OMCUST = (SELECT Account FROM Finance.dbo.tes tAccount WHERE Country = 'SG1' THEN '1')
when OMCOMP = 'SG1' and OMDIM1 = 1234 or OMCUST = (SELECT Account FROM Finance.dbo.tes tAccount WHERE Country = 'SG1' THEN '2')
ELSE 'OTHERS'
END
FROM Finance.dbo.tes tFMOSAL
Basically I want to create a table that would show 'AccountFrom' either in '1' or '2' or ' Others'
In the first instance, if OMCOMP is 'SG1' and OMDIM1 is 1000 or if OMCOMP is 'SG1' and OMCUST is equal to a number in another table where country is SG1 then Accountfrom will be equal to 1
Thanks very much in advance for any expertise anyone can offer on my issue.
Comment