Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help !! Create dynamically table destination


Help !! Create dynamically table destination

Author
Message
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8389 Visits: 19503
Lidou123 (1/10/2013)
Phil,

I will use it like a staging table.

After data in the table, I will use them easily with SSIS and T-SQL.


If the column names and datatypes change every day, it may be easy but it will also be manual. If you're happy with that, you might as well keep the entire process manual and just use the import wizard.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Lidou123
Lidou123
SSC Journeyman
SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)

Group: General Forum Members
Points: 91 Visits: 378
No Sad.

I need to automate the process.

I have a headache. I will go to sleep.

May be tomorrow I will find the solution.

Tomorrow is another day.

Thank U Phil
sqlbi.vvamsi
sqlbi.vvamsi
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 412
try this , you could always play with datatypes once you have data in your table..

string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Documents\\Book1_3.xlsx;Extended Properties='Excel 12.0;HDR=NO;'";

OleDbConnection con = new OleDbConnection(constr);
con.Open();
DataTable dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,null);
con.Close();

SqlConnection sqlcon = new SqlConnection("Server=servername;Database=dbname;Trusted_Connection=True;Integrated Security=SSPI;");

string tblcreate = "Create Table ##TEMP_Excel(";
foreach (DataRow dr in dt.Select("TABLE_NAME='Sheet1$'"))
{
tblcreate = tblcreate + dr["COLUMN_NAME"].ToString() + " varchar(32)" + ",";
}

tblcreate=tblcreate.Substring(0, tblcreate.Length - 1);
tblcreate = tblcreate + " );";
sqlcon.Open();


SqlCommand cmd = new SqlCommand(tblcreate, sqlcon);
cmd.ExecuteNonQuery();
sqlcon.Close();
Lidou123
Lidou123
SSC Journeyman
SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)

Group: General Forum Members
Points: 91 Visits: 378
Thank U for your help. Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search