Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
asm
Posting Yak Master
140 Posts |
Posted - 2007-03-12 : 01:46:11
|
| HiI want to display/delete the tables record from the databasefrom single query or procedure. I am trying this procedure to display the record but error message given.. pls help how to do this..CREATe PROCEDURE spTablesAS DECLARE @TName varchar(100)BEGIN --Declare the Cursor DECLARE C1 CURSOR FOR SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES WHERE Table_Type='BASE TABLE' ORDER BY Table_Name --Open the Cursor OPEN C1 --Fetch the Next Record from Table to Cursor FETCH NEXT FROM C1 INTO @TName --While Loop WHILE (@@FETCH_STATUS = 0) BEGIN PRINT 'Table Name : '+ @TName SELECT * FROM @TName FETCH NEXT FROM C1 INTO @TName END CLOSE C1 DEALLOCATE C1ENDGOThanks |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-12 : 02:04:18
|
quote: Originally posted by asm HiI want to display/delete the tables record from the databasefrom single query or procedure. I am trying this procedure to display the record but error message given.. pls help how to do this..CREATe PROCEDURE spTablesAS DECLARE @TName varchar(100)BEGIN --Declare the Cursor DECLARE C1 CURSOR FOR SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES WHERE Table_Type='BASE TABLE' ORDER BY Table_Name --Open the Cursor OPEN C1 --Fetch the Next Record from Table to Cursor FETCH NEXT FROM C1 INTO @TName --While Loop WHILE (@@FETCH_STATUS = 0) BEGIN PRINT 'Table Name : '+ @TName exec('SELECT * FROM ' + @TName) FETCH NEXT FROM C1 INTO @TName END CLOSE C1 DEALLOCATE C1ENDGOThanks
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
asm
Posting Yak Master
140 Posts |
Posted - 2007-03-12 : 02:18:55
|
| Thanks for your help.. Can you tell how to store the result i get from select statement in a given .txt filethanks |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-12 : 02:25:19
|
| Use BCP command-line tool with QUERYOUT option to do this.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|