473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SQL Case Syntax Issue

3
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.testAccount WHERE Country = 'SG1' THEN '1')
when OMCOMP = 'SG1' and OMDIM1 = 1234 or OMCUST = (SELECT Account FROM Finance.dbo.testAccount WHERE Country = 'SG1' THEN '2')
ELSE 'OTHERS'
END
FROM Finance.dbo.testFMOSAL

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.
Jan 4 '11 #1
1 1572
code green
1,726 Expert 1GB
I don't think
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
Is the same as this
Expand|Select|Wrap|Line Numbers
  1. when OMCOMP = 'SG1' and OMDIM1 = 1000 or OMCUST (SELECT ...
Think about the logic!
I have not looked at the second statement but the first will return true if OMCOMP is 'SG1' and OMDIM1 is 1000
and return true if OMCUST is equal to a number in another.
No other condition will return true
Jan 4 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bob Bedford | last post by:
Hi, I've no Mysql NG access from my ISP, so let me ask here. I've a case statement in mysql. Here is the code: select ...., case myvalue
5
by: Drifter | last post by:
The quote below is part of the information i want to save to a MS Access database - or update, as the case may be. The original database was built a long time ago, and looking at the code for...
9
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
8
by: Penny | last post by:
Hi all, My browser throws this Select Case block back at me pointing out a syntax error on the line: 'Case < 251', between the word 'Case' and the '<' symbol. *************************** ...
8
by: BobTheDatabaseBoy | last post by:
the following syntax is accepted: alter table DB2ADMIN.APPTS add constraint appts_status check (lob_appt_status in ( case when state_code = 'VA' then 'P' -- , 'I' else 'X'
6
by: denero_watz | last post by:
Hello, I have a requirement where I need to return all the ids from Table1 if the column 'name' of Table1 is in (i.e. a substring of) the 'longname' column of Table2. How do I correct my SQL...
12
by: Chief | last post by:
Hey I have a CODE that some 1 wrote however he use this line x= (y=4,z=6); ( by the way the output of this line is x=6 , y=4 , z=6 ) i was wondring in what situation i will have to use it?...
15
by: computerider | last post by:
I have this code which works fine and will open the form to the correct record but it produces a "Type mismatch" msgbox on opening the record... the stLinkCriteria consists of two values one of...
4
by: makinha | last post by:
Hello, I am getting a syntax error Microsoft VBScript compilation error '800a0400' Expected statement line 49 Case 164 To 269 ---------------^ (The error references...
1
jhardman
by: jhardman | last post by:
check out this thread in the asp forum. Poster is using VBscript and is asking a select case syntax question, but is a little too technical for me, I've never heard of trying this. Any of you VBers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.