Click here to Skip to main content
15,885,216 members

Must declare the scalar variable

DINESH K MAURYA asked:

Open original thread
i have create a procedure and after executing it will show error msg.

Please help me
Must declare the scalar variable "@ArticleN".


/****** Object:  StoredProcedure [dbo].[vs_Models_SELECT]    Script Date: 11/20/2012 10:45:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Models]

AS


	SET NOCOUNT OFF;

Declare @CategoryID int
Declare @SubCategoryID int
Declare @SortExpression varchar(100)
Declare @Order varchar(100)
Declare  @ArticleN varchar(150)

set @CategoryID=6  
set @SubCategoryID=1   
set @SortExpression=NULL
set @Order=NULL


if @SortExpression is NULL 
Begin
set @SortExpression='p.SeriesId  '
End

if @Order is NULL 
Begin
set @Order ='Desc  '
End

declare @Sort varchar(200)
set @Sort=@SortExpression + @order
set @ArticleN=N'A P I INDIA';

declare @QueryString nvarchar(max)

		set @QueryString= ' Select  --ProductID ,
				Article_No as Model,
				p.SeriesId,
				s.SeriesDesc,
				p.CategoryId,
				ca.CategoryDesc,
				p.MaterialUsedId,
				m.MaterialUsedDesc,
				p.Size, 
				p.ColorId,
				c.ColorNameDesc,
				p.Gender,
				MRP ,
				p.Manufactured_In,
				Maunfacturing_Date,
				Input_Pairs,
				Soldout_Pairs,
     			Remaining_Pairs

		from tabproduct P
		inner join tblkpSeries s
		on p.SeriesId=s.SeriesId
		inner join tblkpCategory ca
		on p.CategoryId=ca.CategoryId
		inner join tblkpMaterialUsed m
		on p.MaterialUsedId=m.MaterialUsedId

		inner join tblkpColor c
		on p.ColorId=c.ColorId

		where 
   		  
		Manufactured_In=case when  @ArticleN  is null then Manufactured_In
			else @ArticleN
			end
	

		Order by ' + @Sort

PRINT @QueryString
 EXEC (@QueryString)


Thanks in advance..
Tags: SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900