Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Which Column Has the Data?

 
   Database Help (Home) -> Programming RSS
Next:  troubleshooting ado.net ?? displaying parsed sqlc..  
Author Message
xeroxero

External


Since: Oct 16, 2006
Posts: 5



(Msg. 1) Posted: Wed Jan 24, 2007 11:17 am
Post subject: Which Column Has the Data?
Archived from groups: microsoft>public>sqlserver>programming (more info?)

I have a table with 4 columns "ID" "ColA" "ColB" "ColC". One of them
has the value "xxx", the others are null. My SQL is

Select ID From MyTable Where ColA='xxx' or ColB='xxx' or ColC='xxx'

But In addition to ID, I also want to know which column has 'xxx'. How
can I modify my SQL Server 2000 TSQL to know which has the data?

Thanks.

 >> Stay informed about: Which Column Has the Data? 
Back to top
Login to vote
Razvan Socol

External


Since: Feb 03, 2008
Posts: 219



(Msg. 2) Posted: Wed Jan 24, 2007 11:17 am
Post subject: Re: Which Column Has the Data? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Try something like this (untested):

Select ID,
SUBSTRING(CASE WHEN ColA='xxx' THEN ',ColA' ELSE '' END
+CASE WHEN ColB='xxx' THEN ',ColB' ELSE '' END
+CASE WHEN ColC='xxx' THEN ',ColC' ELSE '' END,2,8000) AS Col
>From MyTable Where ColA='xxx' or ColB='xxx' or ColC='xxx'

Razvan

 >> Stay informed about: Which Column Has the Data? 
Back to top
Login to vote
xeroxero

External


Since: Oct 16, 2006
Posts: 5



(Msg. 3) Posted: Thu Jan 25, 2007 10:00 am
Post subject: Re: Which Column Has the Data? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks! That worked perfectly.

On 24 Jan 2007 08:22:48 -0800, "Razvan Socol"
wrote:

>Try something like this (untested):
>
>Select ID,
> SUBSTRING(CASE WHEN ColA='xxx' THEN ',ColA' ELSE '' END
> +CASE WHEN ColB='xxx' THEN ',ColB' ELSE '' END
> +CASE WHEN ColC='xxx' THEN ',ColC' ELSE '' END,2,8000) AS Col
>>From MyTable Where ColA='xxx' or ColB='xxx' or ColC='xxx'
>
>Razvan
 >> Stay informed about: Which Column Has the Data? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Adding Column Data from 2....... - Ok, I have been trying to figureout something for a long time and by that I mean a couple of days..... What I want to do is take the data from two colums and add them together into one column. All three columns have the same properties. nvarchar(19)..

how to change views column data type - OLAP ERROR: unable to open the record set the count-unique aggregate opration cannot take a uniqueidentifier data type as an argument The workaround is to create a view within SQL Server that converts the uniqueidentifier data type column(s) to a char(n...

Limit what type of data gets inserted into a column? - In the table below, I want the StateCode to accept only 2 uppercase letters (A-Z). How do I do this? The datatype is set to AddressStateCode (char(2)) just to clarify its datatype. Would you use check constraints? or rules? CREATE TABLE..

tSQL float data type stores fewer digits than float column.. - Hi all, I encounter suprising behaviour with variables declared with the floating point data type in Transact SQL. Even if I explicitely declare my tSQL variable of the same precision as a field in a table, it will loose many of its digits. Is there a..

set the data type of a derived column in the select statem.. - I run a select statement against a table and have a derived column I would like to populate with a null value as a place holder. The data type needs to be "datetime" Something like this; SELECT start_date, end_date, 'null' AS maturity_date &g...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]