Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

can sql server add columns dynamically Expand / Collapse
Author
Message
Posted Friday, August 15, 2014 10:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 1:18 PM
Points: 2, Visits: 6
I have XML files that need to be put into a table. The problem is that the nodes can range from 1 to ? and inside of some of those nodes some data changes from time to time. usually by one item. So I know how to put a defined amount in database and here I need to be able to change the columns on the fly for any XML document. Can I create columns dynamically each time I load an XML file into a SQL table?
Post #1603786
Posted Friday, August 15, 2014 11:23 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 7:08 PM
Points: 4,046, Visits: 9,205
With SELECT...INTO... you can create a table with the needed columns. However, what would you do next with that data? I assume that you'll insert base columns onto a table. What will you do with the changes in the XML file? How would you handle them?


Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1603797
Posted Friday, August 15, 2014 2:08 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 1:18 PM
Points: 2, Visits: 6
I'm looking to see if I can add columns dynamically to a SQL table
Post #1603872
Posted Friday, August 15, 2014 2:48 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 7:08 PM
Points: 4,046, Visits: 9,205
Yes, you can do it with dynamic sql. The question is why would you do that.
Altering the schema to fit an xml file is wrong and should be done the other way around. You should transform your xml file to fit your predefined schema.



Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1603880
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse