MS SQL2008 query question

bcarneyAEP

New member
Local time
Yesterday, 23:25
Joined
Feb 1, 2012
Messages
8
I am new to SQL and trying to convert a process that is currently run using Access and Excel. I've run into one issue, Excel has a process that evaluates a number of cells and returns a single yes (TRUE) or no (FALSE) in a diffrent cell. I have not been able to figure out how to do this in an SQL query. Any ideas? Here's what I am looking to due in an SQL select query


Rec col1 col2 col3 New COL3 (RESULTS)
1 TRUE TRUE TRUE TRUE
2 TRUE FALSE TRUE TRUE
3 FALSE FALSE TRUE TRUE
4 FALSE FALSE FALSE FALSE


Thanks in advance
Brian
 
if col1 etc contain string values:
Code:
CASE WHEN col1 = 'True' OR col2 = 'True' OR Col3 = 'True'
       THEN 'True'
       ELSE  'False'
      END as Result

If you're using bit columns then replace 'true' with 1 and 'false' with 0 as appropriate.
 
Great! Thanks for the help. I copied your code and modified it to fit the actual names of the fields in the table. There is one issue, the result only returns False, even when the condition is True.. Any addtional suggestions?

Brian
 
Without More information difficult to suggest, I've tested using both bit and varchar() values and the sample works.
 
Great I figured it out!!!! I had aliased the column names and put the alias names in the code. Removed the (As [Alias name]) from the code and everything works.
THANKS!
 
Glad you got it sorted out. :)

You can leave the alises on the output columns, but you need to test the actual column names in the CASE statement, not the alias.
 

Users who are viewing this thread

Back
Top Bottom