question

sand143eep avatar image
sand143eep asked

Needed help related to TSQL for mentioning the results with name in excel attachment

Hi Everyone,

I have a procedure having three select statements where it gives the output through DB mail of 3 results in excel format. client asked to get the results named. like query1results for first select statement, query2results for the second select statement, query3results for the third select statement.

query1results

empid salarydetails

query2results

empid empname

query3results

empname storedetails

please suggest how i can give names to the results in procedure. procedure code is like this:

alter procedure employee

as

select empid,salarydetails from employee

select empid,empname from employee

select empname,storedetails from employee

sql-server-2008-r2tsqlsql server 2012
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
sand143eep avatar image
sand143eep answered

as a work around i declared variables and selected them in between these queries.

Alter procedure employee

AS

declare @rama Varchar(100),@sita varchar(100),@laxmana varchar(100)

set @rama ='query1results'

select @rama

select empid,salarydetails from employee

set @sita= 'Query2results'
select @sita

select empid,empname from employee

set @laxmana= 'Query3results'
select @laxmana

select empname,storedetails from employee

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.