Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
HiImagine I have a table called Details that looks like the below:ID Animal1 Animal2 Animal3 Child1 Child2 Child31 Dog NULL NULL NULL Tom NULL2 NULL NULL Cat Andrew NULL NULL3 NULL Fish NULL NULL NULL Sarah4 Horse NULL NULL NULL Laura NULLI realise it does not make sense as a table, but this is similar to what I have to work with on a much reduced scale...The query I am trying to do is retrieve just an animal and child value from each row. So in row 1 instead of getting each column I just want to get Dog AS Animal and Tom AS Child etc.Is that possible?Thanks
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-11-18 : 11:51:34
yup possible
SELECT COALESCE(Animal1,Animal2,Animal3) AS Animal,COALESCE(Child1,Child2,Child3) AS Child FROM Table
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
dpnadam
Starting Member
29 Posts
Posted - 2010-11-18 : 11:57:20
Wow that was quick. Works great, thanks.
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-11-18 : 12:00:05
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
X002548
Not Just a Number
15586 Posts
Posted - 2010-11-18 : 12:11:11
quote:Originally posted by dpnadam Wow that was quick. Works great, thanks.