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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Combined SQL Statement?

Author  Topic 

viperbyte
Posting Yak Master

132 Posts

Posted - 2011-08-16 : 19:06:28
Hi guys. I don't know how to write sql that is a blank place holder and I don't know how to combine sql statements. I need this for an ASP.Net GridView where the first row of the GridView won't have any data. If a record is made of ID, FirstName, and LastName I would like to do something like this. Select ID, FirstName, LastName From TblContact(this first record should be empty). Plus Select ID, FirstName, LastName From TblContact(This second sql will pull everything). Anyone know how to do this and wana give me a hand? Please.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-08-16 : 20:06:01
Don't know why you'd do that but
SELECT null as ID,null as FirstName,null as LastName
from TblContact
UNION all
SELECT ID, FirstName, LastName
from TblContact

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

viperbyte
Posting Yak Master

132 Posts

Posted - 2011-08-16 : 21:59:39
Thanks Jim. Now I know how to get the nulls and combine statements. I made a mistake with the table and field names. And I needed the empty record after the regular records; so I made the adjustments. But I'm not quite getting the output I need. The regular query returns four records which is all of them but the nulls version returns four empty records when what I need is just one empty record. You've been a great help but do you or anyone know how I can modify this sql to return only one empty record?

SELECT ID, PhoneNumber, PhoneType, PhoneFK
from dbo.tblPhoneNumber
UNION all
SELECT null as ID,null as PhoneNumber, null as PhoneType, null as PhoneFK
from dbo.tblPhoneNumber
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-16 : 22:05:29
[code]
SELECT ID, PhoneNumber, PhoneType, PhoneFK
from dbo.tblPhoneNumber
UNION all
SELECT null as ID,null as PhoneNumber, null as PhoneType, null as PhoneFK
from dbo.tblPhoneNumber
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

viperbyte
Posting Yak Master

132 Posts

Posted - 2011-08-16 : 22:47:22
Perfect results. Thank you :0
Go to Top of Page
   

- Advertisement -