SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Want to display dynamic number of tables in output?


Want to display dynamic number of tables in output?

Author
Message
dragonpms
dragonpms
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 53
Want to display dynamic number of tables in output?

for exemple:

input parameter

@company_id = 2103
@instance_id '1,2,3,4,5,6,7'

i want output table for each instance ID.

so is it possibile in SQL,if its k please help me out............
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33875 Visits: 16649
I've got absolutely no idea what you mean. Please will you supply table DDL in the form of CREATE TABLE statements, sample data in the form of INSERT statements, and expected results.

Thanks
John
dragonpms
dragonpms
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 53
ok ,lets i explain my requirement....

ALTER PROC Multiple_Instance_Value
(
@compnay_ID INT,
@Instance_ID NVARCHAR(MAX)
)
AS
BEGIN
SELECT instance_id,address,company_name,status FROM cmytbl
WHERE company_ID =@company_ID AND instance_id = @instance_id
END


for exemple we passing the input parameter as

EXEC Multiple_Instance_Value @company_id = 201,@instance_id = '1011,1012,1013,1014,1015,1016,1017'

I want output as

insatnce_id: 1011, address: 3 way line, ABC private ltd,1

insatnce_id: 1012, address: 4 way line, DEF private ltd,1

insatnce_id: 1013, address: 5 way line, GHI private ltd,1

insatnce_id: 1014, address: 6 way line, JKL private ltd,1

insatnce_id: 1015, address: 7 way line, MNO private ltd,1

insatnce_id: 1016, address: 8 way line, PQR private ltd,1

In the above we get the each output table by means of instance_id what we passed in the @input parameter of @instance_id.

The output table is not fixed it may vary deponds on the @instance_id.

I think you may understand my requirement,if so please help me out,am waiting for the solution,if any queries please let me know..........
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33875 Visits: 16649
OK, what you're looking for is a function to split a comma-separated list into its individual components. You should be able to find one by searching this site for "splitter function" or something like that. Once you have one of those, you can CROSS APPLY the results against your table to get the output you desire.

John
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)

Group: General Forum Members
Points: 210477 Visits: 41973
dragonpms (4/3/2011)
ok ,lets i explain my requirement....

ALTER PROC Multiple_Instance_Value
(
@compnay_ID INT,
@Instance_ID NVARCHAR(MAX)
)
AS
BEGIN
SELECT instance_id,address,company_name,status FROM cmytbl
WHERE company_ID =@company_ID AND instance_id = @instance_id
END


for exemple we passing the input parameter as

EXEC Multiple_Instance_Value @company_id = 201,@instance_id = '1011,1012,1013,1014,1015,1016,1017'

I want output as

insatnce_id: 1011, address: 3 way line, ABC private ltd,1

insatnce_id: 1012, address: 4 way line, DEF private ltd,1

insatnce_id: 1013, address: 5 way line, GHI private ltd,1

insatnce_id: 1014, address: 6 way line, JKL private ltd,1

insatnce_id: 1015, address: 7 way line, MNO private ltd,1

insatnce_id: 1016, address: 8 way line, PQR private ltd,1

In the above we get the each output table by means of instance_id what we passed in the @input parameter of @instance_id.

The output table is not fixed it may vary deponds on the @instance_id.

I think you may understand my requirement,if so please help me out,am waiting for the solution,if any queries please let me know..........





This is an SQL Server CE forum. IIRC, SQL Server CE cannot use stored procedures nor can you declare variables in any of it's scripts. So let me ask, what version of SQL Server are you really using?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search