SQLTeam.com | Weblogs | Forums

Getting a column with blank values in the resultset

tsql
sql2008

#1

Hi

I want to get two columns which is to be shown in the result set with blank values even though it does not belonging any joining tables.

My required output is this:

UserId OrderId OrderAmt ProductDescription ProductBatch


U6782 O562622 1220
U2621 O272672 876
U1525 O222877 520
U8223 O228820 420

ProductDescription and ProductBatch columns does not belong to any database tables.
It is there to just show the blank values.

I tried something like this:
select U.UserId, O.Orderid, O.OrderAmt, ProductDescription, ProductBatch
FROM
LoginUser U INNER JOIN Orders O
ON U.UserId = O.UserId

But not working. Please help on this.


#2

select U.UserId, O.Orderid, O.OrderAmt, '' as ProductDescription, '' as ProductBatch
FROM
LoginUser U INNER JOIN Orders O
ON U.UserId = O.UserId


#3

Decide how long you want the two columns to be, then CAST an empty string to that length:

SELECT U.UserId, O.Orderid, O.OrderAmt, 
    CAST('' AS varchar(200)) AS ProductDescription, CAST('' AS varchar(50)) AS ProductBatch
FROM
LoginUser U INNER JOIN Orders O
ON U.UserId = O.UserId