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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 > > |
| ||||
| 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 -- |