Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2007, 02:39 AM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replacing null table entries in select result?

Hi!

I need to modify a sql statement, I have a statement like this:

SELECT Name, MyID FROM Persons

Persons:
ID (PK,int,not null)
Name (varchar(250,not null))
MyID (varchar(10,null))

but some of the table entries lack MyID and what would i like is that the result of this select statement
would return 'XXXXXXXXXX' in MyID insted of null for the entries that lack MyID (without modifying db).


thanks alot!

 
Old July 10th, 2007, 03:09 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SELECT Name, ISNULL(MyID, 'XXXXXXXXXX') AS MyID FROM Persons


 
Old July 10th, 2007, 03:38 AM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks alot it works!, now i found out that i also have some entries with '' (empty string). is there an IF for that?

thanks again!!

 
Old July 10th, 2007, 03:43 AM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...found CASE

SELECT
Name
, CASE (MyID)
    when '' then 'XXX'
        when null then 'XXX'
    Else MyID
    End
FROM Persons

thanks alot!
 
Old July 10th, 2007, 12:30 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1) SELECT Name, CASE WHEN MyID > '' THEN MyID ELSE 'XXXXXXXXXX' END AS MyID FROM Persons
2) SELECT Name, ISNULL(NULLIF(MyID, ''), 'XXXXXXXXXX') AS MyID FROM Persons


 
Old July 10th, 2007, 09:28 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Where is this output going???

--Jeff Moden
 
Old July 11th, 2007, 03:10 AM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...to a DataReader, but I do not want to modify app or db, stored procedure is my best option.

thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing a table name with a server variable topshed Classic ASP Basics 3 October 4th, 2007 11:52 PM
Wrong result on select query penta Access 3 May 5th, 2005 09:05 AM
Delete duplicate entries from table expertcalling SQL Server 2000 2 January 2nd, 2005 11:51 PM
Query to Select latest X entries acdsky Classic ASP Databases 3 July 6th, 2004 01:41 AM
Select Statementw where null Tangerine Classic ASP Databases 1 March 22nd, 2004 03:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.