Re: DBNULL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.

.



Relevant Pages

  • Re: [Info-Ingres] Invitation to a quarrel
    ... For the purpose of running my government benefit system, claimants must provide a name, and one or more of three forms of unique ID (Key1, Key2, Key3). ... Having a primary key made from three unique and nullable keysis the natural solution. ...
    (comp.databases.ingres)
  • Re: cheapest way to join several XML into a single one ... (XSLT vs JDOM)
    ... You're still going to have to rely on some "facts" about your XML though ...
    (comp.lang.java.programmer)
  • ini file
    ... key1 = ala-lab ... key2 = ala-amf ... key3 = ala-ima ... key1 = ci-rep ...
    (microsoft.public.dotnet.languages.vb)
  • ini file
    ... key1 = ala-lab ... key2 = ala-amf ... key3 = ala-ima ... key1 = ci-rep ...
    (microsoft.public.dotnet.faqs)
  • DBNULL
    ... key1 = x, ... key3 = z ... And i cant sum 1 in the dbnull return. ... Declare another variable? ...
    (microsoft.public.sqlserver.programming)