|
Home > Archive > microsoft.public.cert.exam.mcsd > October 2002 > SQL server stored procedure problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SQL server stored procedure problem
|
|
|
| You guys are all SQL server expert, I am running into a
problem, please help. Thanks.
I cannot do
DECALRE myCursor CURSOR FOR
EXEC('SELECT col1 FROM ' + @dbName + '.dbo.MyTable')
What shall I do If I cannot determine database name until
run time?
| |
| Jorge Hernandez 2002-10-05, 6:40 pm |
| Neil:
You should do it on this way:
DECLARE @CursorString as varchar(4000)
SELECT @CursorString = 'DECLARE myCursor CURSOR FOR SELECT col1 FROM '
+ @dbName + '.dbo.MyTable'
EXEC(@CursorString)
OPEN myCursor
Hope this help!
Jorge
"neil" <cafeme@yahoo.com> wrote in message
news:13bb01c25e89$829b1fd0$39e
f2ecf@TKMSFTNGXA08...
> You guys are all SQL server expert, I am running into a
> problem, please help. Thanks.
>
> I cannot do
> DECALRE myCursor CURSOR FOR
> EXEC('SELECT col1 FROM ' + @dbName + '.dbo.MyTable')
>
> What shall I do If I cannot determine database name until
> run time?
>
>
| |
|
| Thanks Jorge! it works. Surprisingly, it does not work if
I write
DECLARE @CursorString as varchar(4000)
SELECT @CursorString = 'DECLARE @myCursor CURSOR FOR
SELECT col1 FROM ' + @dbName + '.dbo.MyTable'
EXEC(@CursorString)
OPEN @myCursor
what's the deal here?
>-----Original Message-----
>Neil:
>
>You should do it on this way:
>
> DECLARE @CursorString as varchar(4000)
> SELECT @CursorString = 'DECLARE myCursor CURSOR FOR
SELECT col1 FROM '
> + @dbName
+ '.dbo.MyTable'
> EXEC(@CursorString)
>
> OPEN myCursor
>
>
>Hope this help!
>
>Jorge
>
>
>
>"neil" <cafeme@yahoo.com> wrote in message
> news:13bb01c25e89$829b1fd0$39e
f2ecf@TKMSFTNGXA08...
>> You guys are all SQL server expert, I am running into a
>> problem, please help. Thanks.
>>
>> I cannot do
>> DECALRE myCursor CURSOR FOR
>> EXEC('SELECT col1 FROM ' + @dbName + '.dbo.MyTable')
>>
>> What shall I do If I cannot determine database name
until
>> run time?
>>
>>
>
>
>.
>
| |
| Jorge Hernandez 2002-10-05, 6:40 pm |
| Neil:
You can not use @myCursor 'cause on this way SQL is finding a cursor
variable @myCursor that references a cursor. So you leave it as:
....'DECLARE myCursor......Open myCursor...'
Anyway if you want to use a variable try to at the beginning declare the
variable:
DECLARE @myCursor as Cursor
I have ever done this on this way but should work.
Hope this help!
Jorge
"Neil" <cafeme@yahoo.com> wrote in message
news:166101c25e98$dccd57c0$3be
f2ecf@TKMSFTNGXA10...
> Thanks Jorge! it works. Surprisingly, it does not work if
> I write
> DECLARE @CursorString as varchar(4000)
> SELECT @CursorString = 'DECLARE @myCursor CURSOR FOR
> SELECT col1 FROM ' + @dbName + '.dbo.MyTable'
> EXEC(@CursorString)
> OPEN @myCursor
>
> what's the deal here?
> >-----Original Message-----
> >Neil:
> >
> >You should do it on this way:
> >
> > DECLARE @CursorString as varchar(4000)
> > SELECT @CursorString = 'DECLARE myCursor CURSOR FOR
> SELECT col1 FROM '
> > + @dbName
> + '.dbo.MyTable'
> > EXEC(@CursorString)
> >
> > OPEN myCursor
> >
> >
> >Hope this help!
> >
> >Jorge
> >
> >
> >
> >"neil" <cafeme@yahoo.com> wrote in message
> > news:13bb01c25e89$829b1fd0$39e
f2ecf@TKMSFTNGXA08...
> >> You guys are all SQL server expert, I am running into a
> >> problem, please help. Thanks.
> >>
> >> I cannot do
> >> DECALRE myCursor CURSOR FOR
> >> EXEC('SELECT col1 FROM ' + @dbName + '.dbo.MyTable')
> >>
> >> What shall I do If I cannot determine database name
> until
> >> run time?
> >>
> >>
> >
> >
> >.
> >
|
|
|
|
|