Discussion:
Dynamic SQL- attachment works as a result of this query however the format is wrong the " comes thorugh in the file and all data is dumped in one cell, help please..
(too old to reply)
p***@gmail.com
2014-10-16 14:18:32 UTC
Permalink
SET @Query = 'SET NOCOUNT ON;
SELECT ''"[N Number]"''
, ''"[AE Diagnosis Group Name]"''
, ''"[GP Code]"''
, ''"[GP Name]"''
, ''"[Attendance]"''


UNION ALL

SELECT ''"'' + CONVERT(varchar(150), [N Number] ) + ''"''
, ''"'' + CONVERT(varchar(150), [AE Diagnosis Group Name] ) + ''"''
, ''"'' + CONVERT(varchar(150), [GP Code] ) + ''"''
, ''"'' + CONVERT(varchar(150), [GP Name] ) + ''"''
, ''"'' + CONVERT(varchar(150), [Attendance] ) + ''"''



FROM ##EmailTable2

WHERE PracticeCode = ''' + (SELECT [PracticeCode] FROM ##EmailTable WHERE ID = @i) + ''';'
Erland Sommarskog
2014-10-16 19:29:44 UTC
Permalink
Post by p***@gmail.com
SELECT ''"[N Number]"''
, ''"[AE Diagnosis Group Name]"''
, ''"[GP Code]"''
, ''"[GP Name]"''
, ''"[Attendance]"''
...
You have already asked this question on the MSDN forums,
https://social.technet.microsoft.com/Forums/en-US/21a6dfca-e738-47b0-814f-
66d7ba17b2b4/dynamic-sql-concatenation-not-working?forum=transactsql

People there have been trying to give you some advice. As your posts
have been somewhat terse, they have had to guess what you are up to,
why their answers may not have been on spot.

I suggest that you go back to the original thread and explain from start
to end what you are trying to achieve.
--
Erland Sommarskog, Stockholm, ***@sommarskog.se
Loading...