Avatar of rbhargaw
rbhargawFlag for United States of America

asked on 

Dynamic SQL select query

Below is the output set I want from an SP. I will have count as input parameter to the  SP
so If count in 3 and I want the result to be c1, c2, c3, c4, c5,c6,c7,c8,c9
If the Count is 2, then c1,c2,c3, c4

Output of SP:
 
(OP)            C1            C2            C3           C4            C5            C6    C7          C8            C9

I know we can do like below, how do I do it dynamically?

SELECT '(OP)',           ' C1 ',   'C2', 'C3','C4','C5','C6', 'C7','C8',       'C9'
Microsoft SQL ServerSybase Database

Avatar of undefined
Last Comment
rbhargaw
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

Is the logic of total output columns = parameter value * parameter value? Not clear.

Do you want this just single line output?
If you share the SP code with us you'll have a faster and better help from us.
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of rbhargaw
rbhargaw
Flag of United States of America image

ASKER

@PortletPaul This is the closest to what I want but let me get more clarifications on the requirements as it is not clear to me.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo