SQL query to get multiple rows as output

Subhomoy Chakraborty 106 Reputation points
2023-01-20T10:03:05.5633333+00:00

Hi Team,

I need to get a output of SQL procedure as per the attached file. Pfa..

20220425_130201_Cof_Test.txt

1st Line : Disabled Query paging.

2nd Line : <Blank>

3rd Line : the header names as mentoned

4th Line : ----------------------+--------------------------------+-----

Then the data will come from the table as

SELECT <colname> FROM CoF_Test.

Please help me to get this line through SP.

I think once it is done in SP then using SSIS package the data can be fetched as text file.

SQL Server Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2023-01-20T22:56:09.63+00:00

    So you want to perform this formatting in your store procedure? And on top of that add the headers?

    Yeah, someone who is really good at SQL, and who knows no other languages may do something like this. While I'm good at SQL, I also know Perl, and Perl actually has some good reporting support. And even if Perl would not fit into the environment, I would still try C# or Python. Or simply try to find someone know knows an appropriate client-side language or report writer to do the job.

    Because, SQL is absolutely the wrong venue for this task. SQL is a great language for retrieving data, with lots of filtering, grouping etc. But formatting is best done elsewhere.

    0 comments No comments

  2. Anonymous
    2023-01-23T03:04:54.3666667+00:00

    Hi @Subhomoy Chakraborty

    As Erland says, using SQL in this scenario is not suitable.

    SQL is a query statement. It is able to filter data based on multiple criteria and arrange them in combination as required. But the data it outputs will still be confined to the grid, constrained by rows and columns.

    But what you need is output in report format, which SQL is difficult to do.

    Best regards,

    Percy Tang


    If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.