Author |
Topic |
awaisahmad435
Starting Member
11 Posts |
Posted - 2011-06-01 : 06:11:02
|
i have created a stored procedure which runs Perfect in SQL Server 2008 but producing error in SQL Server 2005... The error isonly one expression can be specified in the select list when the subquery is not introduced with existsthe procedure is below. plz help me where i m wrong...CREATE PROCEDURE Refresh_Lock ASDECLARE @AccountID VARCHAR(100)DECLARE @getAccountID CURSORSET @getAccountID = CURSOR FORSELECT TABLENAMEFROM DBO.TMPOPEN @getAccountIDFETCH NEXTFROM @getAccountID INTO @AccountIDWHILE @@FETCH_STATUS = 0BEGINPRINT @AccountID EXEC('update ' + @AccountID + 'set flag = ''FREE9''where SYSTEMID in (select b.systemidfrom sys.dm_exec_connections aright outer join dbo.TMP b on b.ipaddress = a.client_net_addresswhere a.session_id is nulland b.tablename = ''' + @AccountID + ''')')EXEC('delete from dbo.tmpwhere SYSTEMID in (select b.systemidfrom sys.dm_exec_connections aright outer join dbo.TMP b on b.ipaddress = a.client_net_addresswhere a.session_id is nulland b.tablename = ''' + @AccountID + ''')')FETCH NEXTFROM @getAccountID INTO @AccountIDENDCLOSE @getAccountIDDEALLOCATE @getAccountID |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-01 : 06:29:56
|
Which statement is giving you the error?Check that the set cursor statement is valid in v2005.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
awaisahmad435
Starting Member
11 Posts |
Posted - 2011-06-01 : 08:47:25
|
the problem arises where i use IN clause. 2005 compiler says u cant use IN clause here. use Exists. but Exists clause doestnot solve my problem.....but 2008 compiler doest'n raise any issue and run it perfectly... |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-01 : 09:00:50
|
You can always use an exist to replace an in clause.You have two statements with in clasues - do they both fail?Have you tried executing the query rather than running it in the sp? Try it with just a select statement.Could be something to do with sys.dm_exec_connections.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-06-01 : 09:06:24
|
quote: Originally posted by awaisahmad435 i have created a stored procedure which runs Perfect in SQL Server 2008 but producing error in SQL Server 2005... The error isonly one expression can be specified in the select list when the subquery is not introduced with existsthe procedure is below. plz help me where i m wrong...CREATE PROCEDURE Refresh_Lock ASDECLARE @AccountID VARCHAR(100)DECLARE @getAccountID CURSORSET @getAccountID = CURSOR FORSELECT TABLENAMEFROM DBO.TMPOPEN @getAccountIDFETCH NEXTFROM @getAccountID INTO @AccountIDWHILE @@FETCH_STATUS = 0BEGINPRINT @AccountID EXEC('update ' + @AccountID + 'set flag = ''FREE9''where SYSTEMID in (select b.systemidfrom sys.dm_exec_connections aright outer join dbo.TMP b on b.ipaddress = a.client_net_addresswhere a.session_id is nulland b.tablename = ''' + @AccountID + ''')')EXEC('delete from dbo.tmpwhere SYSTEMID in (select b.systemidfrom sys.dm_exec_connections aright outer join dbo.TMP b on b.ipaddress = a.client_net_addresswhere a.session_id is nulland b.tablename = ''' + @AccountID + ''')')FETCH NEXTFROM @getAccountID INTO @AccountIDENDCLOSE @getAccountIDDEALLOCATE @getAccountID
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
awaisahmad435
Starting Member
11 Posts |
Posted - 2011-06-01 : 09:15:40
|
quote: Originally posted by nigelrivett You can always use an exist to replace an in clause.You have two statements with in clasues - do they both fail?Have you tried executing the query rather than running it in the sp? Try it with just a select statement.Could be something to do with sys.dm_exec_connections.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
but EXIST clause update whole column. and i want to update where systemid matches with subquery.in EXIST clause we cant mention columnname but with IN clause we can mention columnname .....yes my both statements failed. and nothing wrong with sys.dm_exec_connections. im sure |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-01 : 09:55:35
|
Neither in nor exists updates a column - they both filter the rows that get updated.update mytblset ...from mytblt t1where t1.col in (select t2.col from tbl t2)is the same asupdate mytblset ...from mytblt t1where exists (select * from tbl t2 where t2.col = t1.col)>> nothing wrong with sys.dm_exec_connections. im sureCHeck the way it can be used. There might be nothing wrong with it but the implementation in the two versions might restrict the way it can be used. You don't know unless you check.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
awaisahmad435
Starting Member
11 Posts |
Posted - 2011-06-01 : 10:24:09
|
quote: Originally posted by nigelrivett Neither in nor exists updates a column - they both filter the rows that get updated.update mytblset ...from mytblt t1where t1.col in (select t2.col from tbl t2)is the same asupdate mytblset ...from mytblt t1where exists (select * from tbl t2 where t2.col = t1.col)>> nothing wrong with sys.dm_exec_connections. im sureCHeck the way it can be used. There might be nothing wrong with it but the implementation in the two versions might restrict the way it can be used. You don't know unless you check.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
why u use * in 2nd query's subquery. Plz quide me that in wat way EXISTS works. i m still confused...In 2nd query, after where clause EXISTS filters which of column of t1??? i mean to say with IN clause we specify specifically the column which will be filtered. but with EXISTS on the base of which column filter occurs |
 |
|
awaisahmad435
Starting Member
11 Posts |
Posted - 2011-06-01 : 11:19:34
|
can any one reconstruct my query with INNER JOIN...I WANT TO ELIMINATE IN CLASS.... IS THAT POSSIBLEupdate TBL_DEGREE_COURE_MASTER set flag = 'FREE', flagtime = 'Application Crashed' where SYSTEMID IN (select b.systemid from sys.dm_exec_connections a right outer join dbo.tbl_locks b on b.ipaddress = a.client_net_address where a.session_id is null and b.table_name = 'TBL_DEGREE_COURE_MASTER') |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-01 : 11:40:07
|
* just stands for a row - it normally returns all columns but the server recognises that this is an exists clause and just uses whatever indexes are available to run the query most efficiently.To use a join update TBL_DEGREE_COURE_MASTERset flag = 'FREE', flagtime = 'Application Crashed'from TBL_DEGREE_COURE_MASTER tjoin(select b.systemidfrom sys.dm_exec_connections aright outer join dbo.tbl_locks b on b.ipaddress = a.client_net_addresswhere a.session_id is nulland b.table_name = 'TBL_DEGREE_COURE_MASTER') t2on t.SYSTEMID = t2.SYSTEMID==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
awaisahmad435
Starting Member
11 Posts |
Posted - 2011-06-01 : 12:35:55
|
quote: Originally posted by nigelrivett * just stands for a row - it normally returns all columns but the server recognises that this is an exists clause and just uses whatever indexes are available to run the query most efficiently.To use a join update TBL_DEGREE_COURE_MASTERset flag = 'FREE', flagtime = 'Application Crashed'from TBL_DEGREE_COURE_MASTER tjoin(select b.systemidfrom sys.dm_exec_connections aright outer join dbo.tbl_locks b on b.ipaddress = a.client_net_addresswhere a.session_id is nulland b.table_name = 'TBL_DEGREE_COURE_MASTER') t2on t.SYSTEMID = t2.SYSTEMID==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
WOW WORKING PERFECT....THANKS A LOT DEAR.....PLZ DO THE SAME WITH MY SECOND STATEMENT... THAT WASdelete from dbo.tbl_locksWhere SYSTEMID IN (select b.systemid from sys.dm_exec_connections a right outer join dbo.tbl_locks b on b.ipaddress = a.client_net_address where a.session_id is null and b.table_name = 'TBL_DEGREE_COURSE_MASTER') |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-01 : 12:41:15
|
It's very similardelete dbo.tbl_locksfrom dbo.tbl_locks tjoin(select b.systemidfrom sys.dm_exec_connections aright outer join dbo.tbl_locks b on b.ipaddress = a.client_net_addresswhere a.session_id is nulland b.table_name = 'TBL_DEGREE_COURSE_MASTER') t2on t.SYSTEMID = t2.SYSTEMID==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
awaisahmad435
Starting Member
11 Posts |
Posted - 2011-06-01 : 12:45:06
|
quote: Originally posted by nigelrivett It's very similardelete dbo.tbl_locksfrom dbo.tbl_locks tjoin(select b.systemidfrom sys.dm_exec_connections aright outer join dbo.tbl_locks b on b.ipaddress = a.client_net_addresswhere a.session_id is nulland b.table_name = 'TBL_DEGREE_COURSE_MASTER') t2on t.SYSTEMID = t2.SYSTEMID==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
BUNDLE OF THANKS DEAR......UR SO SWEET......I HAVE RUN IT ON SQL SERVER 2008WORKING PERFECTTOMORROW I SHALL RUN IT ON SQL SERVER 2005....THANKS AGAIN |
 |
|
|