INSERT INTO TableName(name,address,........) VALUES ('@name','@address',...........)
In the Insert Command, we have to Write a large no. of Columns & parameter from their values comes.It takes a lot of time and energy..
Query to Create Columns and Parameters dynamically on 1 click...
Query to Create Columns, like : name,address,..........
SELECT STUFF((SELECT COLUMN_NAME+',' as [text()] FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='YourTableName' for xml path('')),1,0,'')
This Query gives all comma separated columns
Query To Create Parameters from values comes ,like @name,@address...
SELECT STUFF((SELECT '@'+COLUMN_NAME+',' as [text()] FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='YourTableName' for xml path('')),1,0,'')
This Query Gives all Comma Separated Parameters
NOTE : Replace YourTableName with your table name
No comments:
Post a Comment