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.
| Author |
Topic |
|
gagani
Posting Yak Master
112 Posts |
Posted - 2011-11-18 : 17:58:09
|
| SELECT p.Name, pr.ProductReviewIDFROM Production.Product pLEFT OUTER JOIN Production.ProductReview prON p.ProductID = pr.ProductIDabove 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? |
 |
|
|
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. |
 |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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 |
 |
|
|
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 correctNot to mention logical relevance!------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|