473,408 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to set a null for a new column in DB2?

Hi everyone,
Who can tell me the syntax like "NULL AS" of SQL Server query in DB2?
I want to write a query like this(SQL Server query):
SELECT ResellerKey, NULL AS CustomerKe
FROM A
UNION
SELECT NULL AS ResellerKey, CustomerKe
FROM B
How to set a null for a new column in DB2?
WHo can tell me?
Any response is appreciate.

Thanks^_^
Winnie
Apr 13 '07 #1
2 7737
Snib
24
Hi everyone,
Who can tell me the syntax like "NULL AS" of SQL Server query in DB2?
I want to write a query like this(SQL Server query):
SELECT ResellerKey, NULL AS CustomerKe
FROM A
UNION
SELECT NULL AS ResellerKey, CustomerKe
FROM B
How to set a null for a new column in DB2?
WHo can tell me?
Any response is appreciate.

Thanks^_^
Winnie
Winnie,

You should be able to do this with the follow Db2 SQL:

SELECT ResellerKey, ''
FROM A
UNION
SELECT '' , CustomerKe
FROM B

If '' does not work then use ' ' - basically the same but with a space between the singel quotes. If ResellerKey or CustomerKe are numeric then just replace '' with 0.

Regards

Snib
Apr 14 '07 #2
kalexin
20
Winnie,

You should be able to do this with the follow Db2 SQL:

SELECT ResellerKey, ''
FROM A
UNION
SELECT '' , CustomerKe
FROM B

If '' does not work then use ' ' - basically the same but with a space between the singel quotes. If ResellerKey or CustomerKe are numeric then just replace '' with 0.

Regards

Snib

Hi Snib,
The null string '' is not a "true" NULL value in DB2. Therefore the above DB2 statement is not equivalent to the SQL server statement.
However, the NULLIF function can be used to "fool" the database and return a true null instead of a null string.


SELECT ResellerKey, NULLIF(1,1)
FROM A
UNION
SELECT NULLIF(1,1) , CustomerKe
FROM B
Apr 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
3
by: A.M. de Jong | last post by:
Reading a lot about Nulls right now I still can't find a Technical reason to use it or not. For what I've understand is this: In an Ingres database a Null column has a standard extra storage...
10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
3
by: iStrain | last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the answer in a way I can make sense out of. I know I should get this, but so far no way... I'm creating tables and doing queries in...
5
by: Robert Stearns | last post by:
Either I missed something, or ALTER TABLE does not have this capability. Is there any way of doing it except DROPping all constraints which mention this table, EXPORTing the data, DROPping the...
7
by: Douglas Buchanan | last post by:
I cannot access certain column values of a list box using code. I have a list box 'lstPrv' populated by the query below. SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,...
3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
6
by: axelsino | last post by:
I know this has been asked before and yes, I have read the section in the documentation about it. But, my question is: If I have setup mysql with strict_trans_tables, will MySQL allow "null"...
3
by: binder | last post by:
I am designing a new table with a few columns that may or may not have a value on each row that is inserted. What issues determine whether to allow a NULL value to be inserted for that column or...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.