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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Adding Null to column

Author  Topic 

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2011-09-29 : 11:26:04
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

52326 Posts

Posted - 2011-09-29 : 12:57:03
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
   

- Advertisement -