Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return a value with space 1

Status
Not open for further replies.

AgentM

MIS
Jun 6, 2001
387
US
I am new to t-SQL and was looking for some help.

Is there a way to display a "space" or Null value in a column when no data is returned for a query.

E.g. If I run the query below
SELECT EMPNAME, EMPMIDDLE Where EMPName='bob'

When I run this query and if there is no Empname as 'bob' then at least one row should be returned. With "bob" in the EMPName columen and "Null" in the EmpMiddle column.

how can I do that in a SELECt Statement

Hope that helps.
thank you for your help
 
Code:
IF EXISTS(SELECT EMPNAME, EMPMIDDLE Where EMPName='bob')
   SELECT EMPNAME, EMPMIDDLE Where EMPName='bob'
ELSE
   SELECT 'bob' AS EMPNAME, CAST(NULL as (type of EMPMIDDLE here) AS EMPMIDDLE

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Hey, in your first statements (both of them) you forgot FROM clause


Code:
IF EXISTS(SELECT 1 from myTable Where EMPName='bob')
   SELECT EMPNAME, EMPMIDDLE from myTable Where EMPName='bob'
ELSE
   SELECT 'bob' AS EMPNAME, CAST(NULL as (type of EMPMIDDLE here) AS EMPMIDDLE
 
[rofl]

Copy and Paste problem :)

That is because AgentM posted the SELECT statement w/o FROM and I even didn't notice this :)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top