We help IT Professionals succeed at work.

Dynamic SQL select query

246 Views
Last Modified: 2017-03-18
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'
Comment
Watch Question

Nitin SontakkeDeveloper
CERTIFIED EXPERT

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

Do you want this just single line output?
Vitor Montalv√£oIT Engineer
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
If you share the SP code with us you'll have a faster and better help from us.
EE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
rbhargawFounder

Author

Commented:
@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.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.