Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my Database, i have 1000 rows and one column have different Status.I need to export the data from the sql server 2005 as per the status into the different worksheets.
ie, I need to create 10 worksheets dynamically and insert the selected columns in a row into the workseets related to that status .please guide me if any Idea's ...


Thanks in Advance,
Posted
Updated 7-Jun-12 7:25am
v4

Use below query:
SQL
DECLARE @myfile varchar(255)
DECLARE @stat int

SET @myfile = 'C:\template.xls'
SET @stat = 1

EXEC ('INSERT INTO
OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',''Excel 8.0;Database=' + @myfile + ';'',
''SELECT * FROM [Sheet1$]'')
SELECT * FROM myTable WHERE [status]=' + @stat + '')
 
Share this answer
 
Comments
VJ Reddy 7-Jun-12 13:48pm    
Good answer. 5!
Maciej Los 7-Jun-12 13:48pm    
Thank you, VJ ;)
codeBegin 8-Jun-12 2:19am    
my 5
Maciej Los 8-Jun-12 6:53am    
Thank you, codeBegin ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900