aeri_q (10/17/2013)
No i dont want to pass table ..Below is the query :
SELECT obj.name AS FK_NAME,
sch.name AS [schema_name],
tab1.name AS
,
col1.name AS [column],
tab2.name AS [referenced_table],
col2.name AS [referenced_column]
FROM sys.foreign_key_columns fkc
INNER JOIN sys.objects obj
ON obj.object_id = fkc.constraint_object_id
INNER JOIN sys.tables tab1
ON tab1.object_id = fkc.parent_object_id
INNER JOIN sys.schemas sch
ON tab1.schema_id = sch.schema_id
INNER JOIN sys.columns col1
ON col1.column_id = parent_column_id AND col1.object_id = tab1.object_id
INNER JOIN sys.tables tab2
ON tab2.object_id = fkc.referenced_object_id
INNER JOIN sys.columns col2
ON col2.column_id = referenced_column_id AND col2.object_id = tab2.object_id
where OBJECT_NAME(referenced_object_id) = 'My_table_name'
this query returns multiple rows .
Now i want a stored procedure which could read each row and insert it into a table .
As I have already stated, I don't think you are being clear here.
Why would you assign the output of the query to parameters before you go on to insert it into a table.
Why do it row by row?
If the query you have specified is within the Stored Procedure it is a simple insert.
If it is being supplied to the Procedure then you can use a Table Valued Parameter to send it all in in one hit.
Unless...
there is a specific reason why you are inserting the data row by row, in which case, I would suggest you post all the code, including the Procedure you wrote to consume the rows so we can may be see if what you are attempting to do?