SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

suriyarupa
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.

visakh16
Very Important crosS Applying yaK Herder

India
52249 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
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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