Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I have created table with 15 column and 100 rows in sql db, I need to get particular data to be displayed in excel by searching any of column value.

Its URGENT reply ASAP,..!
Posted
Comments
Richard MacCutchan 17-Apr-15 11:49am    
No, it's not urgent. And your question is far from clear.
PIEBALDconsult 17-Apr-15 11:59am    
It may be urgent to you, but not to us.
For exporting to Excel you may want to look at SSIS.

SQL
DECLARE @searchstring  NVARCHAR(max)
SET @searchstring = '%SearchedString%'

DECLARE @sql NVARCHAR(max)

SELECT @sql = STUFF((
    SELECT ' UNION ALL SELECT ''' + TABLE_NAME + ''' AS ''table'', ''' + COLUMN_NAME + ''' AS ''column'', ' + COLUMN_NAME + ' AS value' + 
    ' FROM ' + TABLE_SCHEMA + '.' + TABLE_NAME + 
    ' WHERE ' + COLUMN_NAME + ' LIKE ''' + @searchstring + ''''
    FROM INFORMATION_SCHEMA.COLUMNS 
    WHERE DATA_TYPE in ('nvarchar', 'varchar')
    FOR XML PATH('')
) ,1, 11, '')

EXEC (@sql)



Then you can use Excel BI tool to display data in Excel
 
Share this answer
 
 
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