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.
Hi, i have a table which has the column values similar to the one below.StdID StudenName REF1Name REF1ADD REF2NAME REF2ADD001 Rahul Dr.Shiva aaaaa Dr.David bbbbbbbb002 Govind Dr.Brown ccccc003 Sachin Dr.willam dddd Dr.Thomas eeeeeeeeeI am using sql reporting services to generate a report for all students. Basically i am generating a letter for all the references for students. The reports will be generated for each row in the table.I have to give a query which puts each reference in one row. But if the reference is null. it should not generate a row.I mean in the above example StdID 002 does not have REF2Name and REFADD the query should not generate row for this null REF2NameStdID StudenName REF REFADD001 Rahul Dr.Shiva aaaaa001 Rahul Dr.David bbbbbbb002 Govind Dr.Brown ccccc003 Sachin Dr.willam dddd 003 sachin Dr.Thomas eeeeeeeee
DBA in the making
Aged Yak Warrior
638 Posts
Posted - 2010-04-09 : 13:16:12
Does this give you what you need?
SELECT StdID, StudenName, REF1Name AS REF, REF1ADD AS REFADDFROM tableNameWHERE REF1Name IS NOT NULLUNION SELECT StdID, StudenName, REF2NAME, REF2ADDFROM tableName
WHERE REF2Name IS NOT NULL------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee.