My Question:
If we execute Query (Text Format), Im getting Insert statements in result set
Right Now; I'm doing, Copy and Paste the result set in Query window and again running the query to insert into Table.
Is there any way, to execute it Dynamically(instead of copy & paste)
can Any one help with this.
Look into this query:
SET NOCOUNT ON
USE PUBS
GO
Drop Table ##Temp1
GO
Create Table ##Temp1 ( X Varchar (22), Name Varchar (30), Z Varchar (30))
Insert into ##Temp1
select 'select count(*) from ' AS X, Name AS Y, 'Insert into ##1' AS Z
from sysobjects where xtype = 'u'
order by name
-- SELECT * FROM ##Temp1
Drop Table ##1
go
Create Table ##1(Table_Name Varchar(50), No_Of_Rows Int)
select Z + char(10) + 'Select '+ '"' + A.Name + '" ' + 'As Table_Name, ' +
'count(*) As No_of_Rows from '+ A.Name
from sysobjects A , ##Temp1 B
where A.Name = B.Name and xtype = 'U'
order by A.NameEXECUTE should execute your SQL statement
Showing posts with label copy. Show all posts
Showing posts with label copy. Show all posts
Friday, March 30, 2012
Monday, March 19, 2012
How to edit Stored Procedures ?
I have two questions:
1) Is it possible to rename a SQL table –or- copy the content of a table into a new table ?
2) How to replace the renamed or replaced table name inside the code of Stored Procedures that references it ?
1.
Copy only schema
Select * into NewTable from table1 where 1=2;
Copy schema with data
Select * into NewTable from table1;
2.
use "sp_rename" stored procedure
http://doc.ddart.net/mssql/sql70/sp_ra-rz_11.htm
Subscribe to:
Posts (Atom)