473,441 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

Error Must declare the scalar variable "@Dn".? in SQL Server 2005

Expand|Select|Wrap|Line Numbers
  1. /* Create a table */
  2. Create table Department (vDepartmentName char(25),vDepartmentHead char(25))
  3.  
  4. /* Create two variables that would store the values returned by the fetch statement */
  5.  
  6.  
  7. DECLARE @DepartmentName char(25)
  8. DECLARE @DepartmentHead char(25)
  9.  
  10. /* Define the cursor that can be used to access the records of the table,row by row */
  11.  
  12. DECLARE curDepartment cursor for
  13. SELECT vDepartmentName,vDepartmentHead from Department
  14.  
  15. -- Open the cursor
  16.  
  17. OPEN curDepartment
  18.  
  19. -- Fetch the rows into variables
  20.  
  21. FETCH curDepartment into @DepartmentName,@DepartmentHead
  22.  
  23. --Start a loop to display all the rows of the cursor
  24.  
  25. WHILE(@@fetch_status=0)
  26. BEGIN
  27. Print 'Department Name =' + @DepartmentName
  28. Print 'Department Head =' + @DepartmentHead
  29.  
  30. --Fetch the next row from the cursor
  31. FETCH curDepartment into @DepartmentName,@DepartmentHead
  32. END
  33.  
  34. -- Close the cursor
  35.  
  36. CLOSE curDepartment
  37.  
  38. -- Deallocate the cursor
  39.  
  40. DEALLOCATE curDepartment
Aug 1 '10 #1
5 4656
Jerry Winston
145 Expert 100+
Odd, but your code works just fine on my machine. Do you have any other errors, codes, ect to share?
Aug 1 '10 #2
NeoPa
32,556 Expert Mod 16PB
Amit, are you sure this is an exact copy of the code that was run when you received the error message in the title?

I'm guessing that's supposed to be the question as it's not in the main post.

Welcome to Bytes!
Aug 2 '10 #3
NeoPa
32,556 Expert Mod 16PB
Amit, you need to explain the situation here, not simply start a new thread when things appear complicated.
Aug 2 '10 #4
ck9663
2,878 Expert 2GB
You don't have a variable named @dn. I can't even find anything in your code with the letters "dn".

~~ CK
Aug 2 '10 #5
NeoPa
32,556 Expert Mod 16PB
FYI: The OP (Amit) posted a new question which seemed identical except the title reflected the full name of the variable instead of just @dn. I deleted that thread and explained to the OP what he needed to do to progress. We've heard nothing yet, but he may be home after a long day at work if he's working on the subcontinent.
Aug 2 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: G Fernandes | last post by:
Hi, can someone tell me what the following words mean as per C/clc: 1) token 2) token sequence 3) scalar variable 4) vector
3
by: Ken Adeniji | last post by:
Must declare the scalar variable '@FirstName' ContactGridViewWebForm.aspx <aspqlDataSource RunAt="server" ID="SqlDataSourceContact" ...
2
by: Oded Dror | last post by:
Hi there, Please take a look at the source code and tell me whats wrong? Imports System.Data Imports System.Data.SqlClient Partial Class Test Inherits System.Web.UI.Page Const conString As...
1
by: AndrewD | last post by:
when the following SELECT is executed via A cursor to SQL 2005 it works SELECT * FROM LCTRY WHERE LANGUAGE = 'EN' AND CTRY_CODE = :CTRY BUT SELECT * FROM LCTRY WHERE CTRY_CODE = :CTRY...
1
by: Rama Jayapal | last post by:
the following is my code can anybody rectify my problem that i get when running my application "Must declare scalar variable @ID" <asp:GridView ID="GridView1" DataKeyNames="ID" runat="server"...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
2
by: saravana784 | last post by:
USE GO /****** Object: StoredProcedure . Script Date: 06/09/2007 20:15:29 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO
3
by: ashokakr | last post by:
Hi all This my procedure, when i try to run the procedure it says "coitem_linenumber" is not a scalar variable. Can any one say what is the error and how i can correct it declare wotype...
1
by: Mark | last post by:
I am really struggling with this, trying to understand why it doesn't work. I've simplified the code down to the essentials. The GridView displays in ReadOnly mode just fine, Clicking the "edit"...
1
by: Tony M | last post by:
vs 2005 - vb .net - web forms - xp pro Can't figure out why I keep getting the error Must declare the scalar variable "@CheckUser". The error happens on SqlDA.Fill(SqlDS). Just trying to make...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.