i have a table Companiesdata
CREATE TABLE [dbo].[Companiesdata] ( [Company Name] nvarchar(255) NULL, [ParentId] int NULL, )
the records are
Now i have another table companynames
create table [dbo].[companynames] ( companyname varchar(max) )
Now i want to write a procedure such that when i give multiple parentids like ex: 1,2 the companyname corresponding to the ids ( here ids 1,2) must insert into companynames table.
I want the out put as:
exec parentid 1,2
the records must be displayed as
You can pass the parameter as comma delimited string and us eg. the CSV spillting function by Jeff Moden (Tally OH! An Improved SQL 8K “CSV Splitter” Function or CLR Splitter on SQL Server 2005+ (Fastest CSV strings splitting using CLR (T-SQL vs. CLR revisited)).
Using the Jeff Moden's function you can use have a stored proc something like:
Than you can call it using:
answered Aug 02, 2012 at 01:15 PM