|
| Union Question |
 |
3 Mar 2008 18:53:18 -0700 |
I have a union that goes something like this:
select A, B from table1
union all
select X, Y from table2
but in my case, I need to cast col Y to a null in the second select, so
the union turns into
select A, B from table1
union all
select X, cast(null as varchar(10)) from table2
The VarChar(10) is the size of col B. Hardcoding the size of the
varchar in this situation seem awkward, but appears to be necessary.
What I tried (but it didnt work) is using a domain instead of the
varchar cast.
* Doesnt work
select A, B from table1
union all
select X, cast(null as MyDomainType) from table2
My concern is that during maintenance updates, the column size could
change which could inadvertantly affect the union. This column size
dependence isn't readily apparent. Specially for new folks that may be
maintaining the database.
Is there any other way to make this kind of SQL more generic so the
casting is based on the actual column type so that you could make a
size change in one place?
--
|
| Post Reply
|
| Re: Union Question |
 |
Tue, 4 Mar 2008 08:36:53 +0100 |
> Is there any other way to make this kind of SQL more generic so the
> casting is based on the actual column type so that you could make a
> size change in one place?
Not currently, no.
--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com
|
| Post Reply
|
|
|
|
|
|
|
|
|
|