Re: "Must declare the scalar variable @Nickname"...
From: bruce barker (nospam_brubar_at_safeco.com)
Date: 07/09/04
- Next message: Jos: "Re: send mail with remote smtp"
- Previous message: Peter Blum: "Re: problem with ASP.NET Validator Control in 2 Form"
- In reply to: Jiggaz: ""Must declare the scalar variable @Nickname"..."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 9 Jul 2004 09:11:44 -0700
dynamic sql runs in its own context (think of it as a sub call), so no
variables declared in the caller are valid in the dynamic statement. i have
no idea why you used dynamic sql or declared @checkforexistingrecord as a
varchar.
try:
declare @checkForExistingRecord int
if exists (select * from users where nickname = @usernick)
set @checkForExistingRecord = 1
else
set @checkForExistingRecord = 0
-- bruce (sqlwork.com)
"Jiggaz" <anonymous@discussions.microsoft.com> wrote in message
news:2a52b01c465a7$a1ef12c0$a301280a@phx.gbl...
> Hi,
>
> Look my stored procedure :
> __________________
> ALTER PROCEDURE dbo.CreateAccount
>
> @Nickname varchar(30),
> @Password varchar(15),
> @Email varchar(50),
> @Date datetime,
> @Name varchar(50),
> @Lastname varchar(50),
> @Sexe varchar(2),
> @Titre varchar(15),
> @Adress varchar(255),
> @Birthday varchar(50),
> @Phonetel varchar(50),
> @Mobilephone varchar(50),
> @Website varchar(255),
> @MailsAllowed varchar(2)
>
> AS
>
> DECLARE @insertstring nchar(4000)
> DECLARE @checkforexistingrecord VARCHAR(60)
> DECLARE @add VARCHAR(2000)
> DECLARE @usernick VARCHAR(30)
>
> SET @usernick = @Nickname
>
> SET @insertstring = 'DECLARE @checkforexistingrecord
> VARCHAR(60)
> SELECT nickname FROM users WHERE nickname = '''
> + @usernick + ''''
> EXEC(@insertstring)
> SELECT @checkforexistingrecord = @@ROWCOUNT
> __________________
>
> Why i get this error?
> I just want to verify if the username already exists..
>
> Thanks. Regards.
- Next message: Jos: "Re: send mail with remote smtp"
- Previous message: Peter Blum: "Re: problem with ASP.NET Validator Control in 2 Form"
- In reply to: Jiggaz: ""Must declare the scalar variable @Nickname"..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|