SQL help (numpty alert)
Discussion
As part of a larger query I need to do this:
IF that field is not blank
select an entry from a varchar field in table 1
ELSE
Select a date from a date field in table 2 (which is never blank)
This task has beaten my barely mentionable SQL skills, can anyone point me in the right direction?
Thanks!
IF that field is not blank
select an entry from a varchar field in table 1
ELSE
Select a date from a date field in table 2 (which is never blank)
This task has beaten my barely mentionable SQL skills, can anyone point me in the right direction?
Thanks!
SELECT
CASE
WHEN ISNULL(TABLE1.VARCHARFIELD,'') = '' THEN CONVERT(varchar(50),TABLE2.DATEFIELD)
ELSE VARCHARFIELD
END AS THEFIELDIWANTED
FROM TABLE1
INNER JOIN TABLE2 on TABLE2.JOINFIELD = TABLE1.JOINFIELD
This sort of thing. You need the "CASE" clause. You can always shove subqueries in if you need.
CASE
WHEN ISNULL(TABLE1.VARCHARFIELD,'') = '' THEN CONVERT(varchar(50),TABLE2.DATEFIELD)
ELSE VARCHARFIELD
END AS THEFIELDIWANTED
FROM TABLE1
INNER JOIN TABLE2 on TABLE2.JOINFIELD = TABLE1.JOINFIELD
This sort of thing. You need the "CASE" clause. You can always shove subqueries in if you need.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


