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 ««12

Help !! Create dynamically table destination Expand / Collapse
Author
Message
Posted Thursday, January 10, 2013 2:13 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:24 AM
Points: 5,258, Visits: 12,189
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1405642
Posted Thursday, January 10, 2013 2:39 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 12:13 PM
Points: 69, Visits: 289
No .

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
Post #1405648
Posted Tuesday, January 22, 2013 10:43 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: 2 days ago @ 5:36 PM
Points: 54, Visits: 383
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();
Post #1410160
Posted Friday, January 25, 2013 11:45 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 12:13 PM
Points: 69, Visits: 289
Thank U for your help. :)
Post #1411874
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse