RE: "Must declare the scalar variable @Nickname"...

From: Scott Simons (Scott.Simons.At.MealMagic.Com.Remove.This)
Date: 07/09/04


Date: Fri, 9 Jul 2004 08:14:02 -0700

I don't mean to be rude but that is the worst sql statement I have ever seen in my entire life. I don't even know where to begin. Why did you use dynamic sql? Why did you declare @checkforexisting record in your dynamic sql? Why did you set @usernick = @Nickname? Why is @Mailsallowed varchar(2)? No really, I want to know why. Sorry, if I come across as rude I'm just trying to understand why you wrote the procedure this way and how you learned to write sql in this way.

"Jiggaz" wrote:

> 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.
>



Relevant Pages

  • Re: Gridview Hidden DateTime column value update problem
    ... Are you not loosing your data when converting the text data to DateTime? ... why don't you receive the parameter in the stored procedure as ... I have a GridView and a SqlDataSource controls on a page. ... datetime value that is held in the template column does not equal the ...
    (microsoft.public.dotnet.general)
  • Re: Using CASE .. WHEN to have dynamic sort
    ... > I'm trying to create a Stored Procedure that returns a recordset, ... > The conversion of a char data type to a datetime data type resulted in ... > an out-of-range datetime value. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Stored Procedure degraded to much slower than direct query
    ... The problem I have boils down to the following: if I run the stored procedure ... from the client process in between background processes' "SQL Transaction" ... The database is in a SQL Server 2000 standard ed. on a Windows 2003 server. ... @StartDate datetime, @EndDate datetime, @TimeOffset int ...
    (microsoft.public.sqlserver.programming)
  • Re: Gridview Hidden DateTime column value update problem
    ... Are you not loosing your data when converting the text data to DateTime? ... why don't you receive the parameter in the stored procedure as ... datetime value that is held in the template column does not equal the ...
    (microsoft.public.dotnet.general)
  • Re: DTS bug (?): Data Driven Query Task removes milliseconds from DATETIME?
    ... by virtue of the fact that it's going through ActiveX script. ... datetime, but still have my stored procedure parameter be a datetime and rely on implicit ... the millisecond component. ... During the invocation of the stored procedure, ...
    (microsoft.public.sqlserver.server)