I have a select statement and I want to say if this select statement does not return any rows then put a '' in every cell. How do I do this?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
It sounds like you're still not getting all the rows you want. True? I think @Joe Sefanelli provides an important part to your solution, and then mentions that you need to change INNER to LEFT joins.
So, you say you want to display all units in your units list. And, if there's no data for a unit, then display the unit and blanks for the data that doesn't exist.
Here's a possible solution. Change your FROM clause to the following:
With this change you will get a list of units that are in the @Units list. The left outer joins will include data associated with each unit, but will not exclude units if there is no associated data.
But make sure you understand that
''
may have a different datatype than columnsa
,b
, andc
.Put your blank row select at the bottom of a union
Based on the posted code, I think you're looking to blank out the columns from the UnitType table as that's the only one you're left-joining to. In that case use
max returns a
null
where not have rows thenisnull
function returns' '
instead anull
valueTry this -