Re: DBNULL
- From: "Dan Guzman" <guzmanda@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 20 Jun 2009 20:44:14 -0500
And i cant sum 1 in the dbnull return. I tried too:
if @index = null
set @index = 1
@index will remain NULL of no rows are returned by SELECT. Following the SELECT, you need to use IS NULL rather than equality: Try:
IF @index IS NULL
SET @index = 1
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"André Freitas" <thevirus@xxxxxxxxxx> wrote in message news:ej13fTg8JHA.4172@xxxxxxxxxxxxxxxxxxxxxxx
I got the following code to get the last id from a table
DECLARE @index INT
SELECT TOP 1
@index = id
FROM table
WHERE
key1 = x,
key2 = y,
key3 = z
ORDER BY id DESC
The problem occurs when i get dbnull. I tried:
SELECT TOP 1
@index = id + 1
FROM table
WHERE
key1 = x,
key2 = y,
key3 = z
ORDER BY id DESC
And i cant sum 1 in the dbnull return. I tried too:
if @index = null
set @index = 1
No success to. What can i do? Declare another variable?
(Sorry poor english)
Regards.
.
- References:
- DBNULL
- From: André Freitas
- DBNULL
- Prev by Date: Re: DBNULL
- Next by Date: Converting MS Access datetime to SQL
- Previous by thread: Re: DBNULL
- Next by thread: Re: DBNULL
- Index(es):
Relevant Pages
|