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
 General SQL Server Forums
 New to SQL Server Programming
 blank in place of null

Author  Topic 

gagani
Posting Yak Master

112 Posts

Posted - 2011-11-18 : 17:58:09
SELECT p.Name, pr.ProductReviewID
FROM Production.Product p
LEFT OUTER JOIN Production.ProductReview pr
ON p.ProductID = pr.ProductID

above query returns null if there is no match of productID.
I want a blank in place of null.
I tried isnull(columnname, '') but is returning 0.
Can anyone help please

mgonda
Starting Member

29 Posts

Posted - 2011-11-18 : 18:09:14
I'm not an expert, and may be misreading the question, but did you try a RIGHT OUTER JOIN instead of LEFT?
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-18 : 22:36:59
It's returning a zero because it's and integer data type, not a character data type.

Not sure why you want to do this (you should handle that type of formatting in the front end) but you'll need to cast the result to a character data type if you want to represent it as a string.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-19 : 01:53:52
just to further clarify,isnull converts the type of result to type of first argument. as Russell pointed out you need to cast it to varchar if you need to return a blank. But didnt understand meaning of returning value as '' for numeric data though

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

johntech
Yak Posting Veteran

51 Posts

Posted - 2011-11-21 : 03:58:20
Sum(Cast(IsNull(' + @ColumnName + ',0) as int))'

Try the above code for casting to use isnull function with int
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-21 : 04:01:12
quote:
Originally posted by johntech

Sum(Cast(IsNull(' + @ColumnName + ',0) as int))'

Try the above code for casting to use isnull function with int


hmm?
this is not even syntactically correct
Not to mention logical relevance!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -