November 17, 2003 at 2:41 pm
Hello
I am trying to create a query that brings back a recordset that will have an alias that if one colunmn from table 1 (2002 info) has a null it is replaced with a column from table 2 (2003 info) for an aspx page. I think there should be a way to do this using a view or something?
Would case do this for me? Unfortunately I have not been able to get this correctly as of yet
Thank you for any help you can give me
Karen
November 17, 2003 at 3:08 pm
You're probably looking to use ISNULL(). Something like:
SELECT ISNULL(t1.col1,t2.col2)
FROM table1 t1, table2 t2
WHERE ....
The t2.col2 could also be a seperate SELECT statement if the tables don't join in the query, but I don't know enough about your data to tell you if that's the most efficient way of handling this case.
Jeff
November 17, 2003 at 3:19 pm
ISNULL will only return a second value if the first is NULL. If you need to expand on this, you will want to use COALESCE. It will return the first non-NULL value from the column list. If all are NULL, it will return NULL.
SELECT COALESCE(t1.col1,t2.col2, t2.col3)
FROM ....
Brian
November 18, 2003 at 5:10 am
Jeff, Brian
Thank you!!!! I think this will work for me.
November 18, 2003 at 7:36 am
Jeff, Brian
Thank you!!!! I think this will work for me.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply