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
 Transact-SQL (2000)
 Setting variable based on select statement

Author  Topic 

corey
Starting Member

13 Posts

Posted - 2004-11-30 : 15:36:41
Second post today...I don't know what is wrong with me but I am having serious issues.

Can someone see what I am doing wrong?

DECLARE @new_seq int
IF (SELECT image_seq
FROM sysadm.picture_it
WHERE image_id = 'A000077') isnull
BEGIN
SET @new_seq = '1'
END
ELSE
BEGIN
SET @new_seq = (SELECT MAX(image_seq)
FROM sysadm.picture_it
WHERE image_id = 'A000077')
SET @new_seq = @new_seq + 1
END
SELECT @new_seq

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-11-30 : 15:41:38
Are you getting an error?

The IF statement should say IS NULL not one word. And the first SET should be SET @new_seq = 1 not the string 1.

The second SET is easier if you do this:

SELECT @new_seq = MAX(image_seq)
FROM ...
WHERE ...

Tara
Go to Top of Page

corey
Starting Member

13 Posts

Posted - 2004-11-30 : 15:46:17
Once again...I knew I was overlooking something silly. Thanks for the corrections. Much, much, much appreciated!
Go to Top of Page
   

- Advertisement -