SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Adding Null to column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

trouble2
Constraint Violating Yak Guru

Netherlands
267 Posts

Posted - 09/29/2011 :  11:26:04  Show Profile  Reply with Quote
I had some problems inserting null values, so I tried to do this:

INSERT INTO
[TableName]
(
[SomeID],
[ForeignKeyID]
)
VALUES
(
@SomeID,
(SELECT CASE
WHEN @ForeignKeyID = -1 THEN NULL
ELSE @ForeignKeyID
END)

However SQL 2000 says: Subqueries are not allowed in this context. Only scalar expressions are allowed.

So how can I solve this?

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 09/29/2011 :  12:57:03  Show Profile  Reply with Quote
make it like


INSERT INTO
[TableName]
(
[SomeID],
[ForeignKeyID]
)
SELECT 
@SomeID,
NULLIF(@ForeignKeyID,-1)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000