SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Return value if field not there in Query


Return value if field not there in Query

Author
Message
tibco29
tibco29
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 147
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?
Kingston Dhasian
Kingston Dhasian
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3751 Visits: 5180
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/
Amit Raut
Amit Raut
SSC Eights!
SSC Eights! (915 reputation)SSC Eights! (915 reputation)SSC Eights! (915 reputation)SSC Eights! (915 reputation)SSC Eights! (915 reputation)SSC Eights! (915 reputation)SSC Eights! (915 reputation)SSC Eights! (915 reputation)

Group: General Forum Members
Points: 915 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?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search