Unix Technical Forum

Select qry is not working properly

This is a discussion on Select qry is not working properly within the MS SQL ODBC forums, part of the Microsoft SQL Server category; --> Hello, I am writing an sql qry for cursor function. the Select qry is not working properly. please check ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > MS SQL ODBC

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 08:55 PM
K R Lal
 
Posts: n/a
Default Select qry is not working properly

Hello,

I am writing an sql qry for cursor function. the Select qry is not working
properly. please check this and help me

declare @m as varchar(20)
declare @mm as varchar(400)
set @m='r-01,r-002'
set @m=char(39)+replace(@m,',',char(39)+', '+char(39))+char(39)
select @m
set @mm ='select * from masteritem where refnumber in ('+ @m+ ')'
exec (@mm)
this work on normal mode but the last 2 line I want to put after declaring
the cursor. There the set command is not working.

if I do like this

declare @m as varchar(20)
declare @mm as varchar(400)
set @m='r-01,r-002'
set @m=char(39)+replace(@m,',',char(39)+', '+char(39))+char(39)
select @m
select * from masteritem where refnumber in ( @m)

no result

Please help me.

Thank and regards

Lal


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 08:55 PM
Nik Marshall-Blank
 
Posts: n/a
Default Re: Select qry is not working properly

I can't see any CURSOR declarations here,please post complete code.

--
Nik Marshall-Blank MCSD/MCDBA

"K R Lal" <lal9@yahoo.com> wrote in message
news:u2UNFGBwFHA.3300@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I am writing an sql qry for cursor function. the Select qry is not working
> properly. please check this and help me
>
> declare @m as varchar(20)
> declare @mm as varchar(400)
> set @m='r-01,r-002'
> set @m=char(39)+replace(@m,',',char(39)+', '+char(39))+char(39)
> select @m
> set @mm ='select * from masteritem where refnumber in ('+ @m+ ')'
> exec (@mm)
> this work on normal mode but the last 2 line I want to put after declaring
> the cursor. There the set command is not working.
>
> if I do like this
>
> declare @m as varchar(20)
> declare @mm as varchar(400)
> set @m='r-01,r-002'
> set @m=char(39)+replace(@m,',',char(39)+', '+char(39))+char(39)
> select @m
> select * from masteritem where refnumber in ( @m)
>
> no result
>
> Please help me.
>
> Thank and regards
>
> Lal
>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 08:55 PM
David Portas
 
Posts: n/a
Default Re: Select qry is not working properly

To implement a dynamic cursor declaration requires either that you
create a global cursor or that you use sp_executesql to return a cursor
variable. Of course the smart solution is usually to avoid using
cursors at all...

--
David Portas
SQL Server MVP
--

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:25 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com