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 |
function
Starting Member
12 Posts |
Posted - 2009-11-23 : 07:53:46
|
Hi guys,I have 2 tables as follows:FIRST TABLE:===============firsttable_id, perigrafi_id (coming from another table), first_decodeSECOND TABLE:===============secondtable_id, perigrafi_id (the same as above), second_encodeAll i want to do is a union statement as follows:SELECT '' as [first_encode]from firsttable where perigrafi_id=1unionSELECT second_encodefrom secondtable where perigrafi_id=1But the result is like this:=============================01instead of '' (empty space quote)1How can i achieve the second result with a case statement?Thanks in advance! |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-23 : 08:21:51
|
It is the formation issues.Just return as such but suppress in .NETorSELECT '' as [first_encode]from firsttable where perigrafi_id=1unionSELECT cast(second_encode as varchar(10))from secondtable where perigrafi_id=1MadhivananFailing to plan is Planning to fail |
 |
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-11-23 : 08:30:45
|
Hi functionSELECT statement within the UNION must have the same number of columns and must also have the similar data types.-------------------------R... |
 |
|
function
Starting Member
12 Posts |
Posted - 2009-11-23 : 08:38:14
|
Thank you all guys. It worked like a charm! |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|