﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / T-SQL  / Cursors and variables / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 01:22:53 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Cursors and variables</title><link>http://www.sqlservercentral.com/Forums/Topic508460-8-1.aspx</link><description>I think you're misunderstanding what is going on. The DECLARE CURSOR does use the variable as it's defined at the time when the DECLARE is issued.  Meaning - in programmer terminology - the DECLARE CURSOR sets up and initializes the cursor in one statement.  There's no deferred resolution going on.  The only thing that hasn't happened yet is that the cursor hasn't been materialized (which occurs with the OPEN statement).In this case you get nothing, since at the time of the declare - the variable is NULL.This is normal behavior and to be expected.</description><pubDate>Thu, 29 May 2008 09:22:28 GMT</pubDate><dc:creator>Matt Miller (#4)</dc:creator></item><item><title>RE: Cursors and variables</title><link>http://www.sqlservercentral.com/Forums/Topic508460-8-1.aspx</link><description>Hi,Not sure if this is normal.I have never used a cursor in my life :-) (very happy about that)Do you have to use a cursor for this problem?ThanksChris</description><pubDate>Thu, 29 May 2008 09:13:13 GMT</pubDate><dc:creator>Christopher Stobbs</dc:creator></item><item><title>Cursors and variables</title><link>http://www.sqlservercentral.com/Forums/Topic508460-8-1.aspx</link><description>Hi,Im trying to use a variable within a cursor but I actually populate the variable after the cursor declaration and it doesn't appear to use the value. I created code for a sample as the code this is not working in is rather long and would be confusing if I posted itMy question is  ... Is this NORMAL behavior ?For exampledeclare @tab_name varchar(200), @res_name varchar(200)--set @tab_name = 'sysowners' -- uncomment this line and the cursor will return a value--declare sample cursor for select name from sysobjectswhere lower(name) = lower(@tab_name)--set @tab_name = 'sysowners'open samplefetch sample into @res_namewhile @@fetch_status = 0 begin  print @res_name  fetch sample into @res_nameendclose sampledeallocate sample</description><pubDate>Thu, 29 May 2008 09:00:59 GMT</pubDate><dc:creator>jsmith7290</dc:creator></item></channel></rss>