Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to insert columns dynamically
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

19 Posts

Posted - 03/22/2013 :  02:34:28  Show Profile  Reply with Quote
I have a table Region. It contains 6 columns as CutomerName, Northregion, southregion, Westregion, eastregion and northeastregion.

Now i want to insert values to Region table. From one SP i aam calculating Volumes for each regions. EG. Exec SP_Getvolume 'Input'.

Input for SP is brand name. For each brand, and for each region it will return the volumes of each customers. Result of SP will be like this.

CustomerName NorthRegion SouthRegion Eastregion
C1 234.56 789.45 980.8
C2 43.7 578.98 3243.90

Now i want to insert this output to my Region table. Here for each brands no. of columns will be changing. So dynamically i want to insert all columns whatever SP is returning.

Please help me.

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 03/22/2013 :  05:34:57  Show Profile  Reply with Quote
this is not a good way to design the system. If purpose of procedure is only to return columns for saving it in your Region table I would suggest making it table valued UDF and then always return all the regions. In case of no values for one put a place holder (NULL or 0 based on your system rule). then you can write a simple static UPDATE to join your table to UDF and update values of columns after checking if value is available.

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000