Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Return value if field not there in Query Expand / Collapse
Author
Message
Posted Wednesday, September 11, 2013 4:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, September 18, 2014 1:47 AM
Points: 9, Visits: 82
I want to check field/column exist or not in a table and populate the value

Example: Does the column1,column2 exists:

case1:return column1 and column2

case2:return column1 or column2

case3:return column1

case4:return column2

case5:return '0'(no columns)



How can I achieve this?
Post #1493543
Posted Wednesday, September 11, 2013 4:17 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 2:25 AM
Points: 2,658, Visits: 4,733
Your explanation is not very clear enough. What do you mean by return( return a value or a result or a column name or ... )?

You can use the INFORMATION_SCHEMA.COLUMNS view to check if a particular column exists in a table.



Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1493551
Posted Tuesday, September 24, 2013 12:16 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, April 1, 2014 6:12 PM
Points: 827, Visits: 342
tibco29 (9/11/2013)
I want to check field/column exist or not in a table and populate the value

Example: Does the column1,column2 exists:

case1:return column1 and column2

case2:return column1 or column2

case3:return column1

case4:return column2

case5:return '0'(no columns)



How can I achieve this?



I think what you mean is: If column1 exists then populate column1 with a particular value else ignore. Right?
Post #1497662
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse