Friday, March 30, 2012
reading a txt file
On of the fileds in the txt file has a date 08/06/2007 (for example)
I need to read that into my field in my table that is set as datetime.
Is there somethign special that need to get done? When I try, i get teh
following error:
Conversion invalid for datatypes on column pair 1 (source column
'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)
On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
> I import data by omporting a txt file that is tab delimited.
> On of the fileds in the txt file has a date 08/06/2007 (for example)
> I need to read that into my field in my table that is set as datetime.
> Is there somethign special that need to get done? When I try, i get teh
> following error:
> Conversion invalid for datatypes on column pair 1 (source column
> 'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)
You should change the source data type to datetime or use text for
both.
|||it's a text file.
Before I export it to a text file, I have it formated as datetime in excel.
"SB" <othellomy@.yahoo.com> wrote in message
news:1186485944.181307.110770@.w3g2000hsg.googlegro ups.com...
> On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
> You should change the source data type to datetime or use text for
> both.
>
|||On Aug 8, 3:51 am, "Johnfli" <j...@.ivhs.us> wrote:
> it's a text file.
> Before I export it to a text file, I have it formated as datetime in excel.
> "SB" <othell...@.yahoo.com> wrote in message
> news:1186485944.181307.110770@.w3g2000hsg.googlegro ups.com...
>
>
>
>
> - Show quoted text -
Hi,
I think it be easier if you import the text file AS IS that is all
columns as text (including the column with datetime) you can call it
Excel_to_text_TEMP. Once you have this table imported in the server
you can populate your main table from this temp table and use a
conversion function for datetime etc. HTH.
|||I do intailly load it into a tmp table, as after its in teh temps table, I
have it go and only copy new original records into the main table, I also
have it update exsisting records. so with that said...
How do I convert it to datetime as it goes from the tmp table to teh main
table?
I am not an sql master or anythign, heck, i'm not ever a sql novice lol
so please have your example as clear as possible..
THANK YOU
"SB" <othellomy@.yahoo.com> wrote in message
news:1186545477.061884.9860@.19g2000hsx.googlegroup s.com...
> On Aug 8, 3:51 am, "Johnfli" <j...@.ivhs.us> wrote:
> Hi,
> I think it be easier if you import the text file AS IS that is all
> columns as text (including the column with datetime) you can call it
> Excel_to_text_TEMP. Once you have this table imported in the server
> you can populate your main table from this temp table and use a
> conversion function for datetime etc. HTH.
>
|||On Aug 8, 10:06 pm, "Johnfli" <j...@.ivhs.us> wrote:
> I do intailly load it into a tmp table, as after its in teh temps table, I
> have it go and only copy new original records into the main table, I also
> have it update exsisting records. so with that said...
> How do I convert it to datetime as it goes from the tmp table to teh main
> table?
> I am not an sql master or anythign, heck, i'm not ever a sql novice lol
> so please have your example as clear as possible..
> THANK YOU
> "SB" <othell...@.yahoo.com> wrote in message
> news:1186545477.061884.9860@.19g2000hsx.googlegroup s.com...
>
>
>
>
>
>
> - Show quoted text -
Hi,
Then you should drop the TEMP table and re-create it where all columns
should be varchar(255) or varchar(1000) etc. Then once the temp table
is loaded you should run a query such as (preferably in a sored
procedure, see Books online for syntax):
insert Excel_To_Text (
column1,
column2,
etc...,
date_Column1,
etc...)
select column1,
column2,
etc...,
convert(datetime,Date_Column1),
etc...
from Excel_To_Text_TEMP
Let me know if you have questions. Regards,
SB
reading a txt file
On of the fileds in the txt file has a date 08/06/2007 (for example)
I need to read that into my field in my table that is set as datetime.
Is there somethign special that need to get done? When I try, i get teh
following error:
Conversion invalid for datatypes on column pair 1 (source column
'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
> I import data by omporting a txt file that is tab delimited.
> On of the fileds in the txt file has a date 08/06/2007 (for example)
> I need to read that into my field in my table that is set as datetime.
> Is there somethign special that need to get done? When I try, i get teh
> following error:
> Conversion invalid for datatypes on column pair 1 (source column
> 'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)
You should change the source data type to datetime or use text for
both.|||it's a text file.
Before I export it to a text file, I have it formated as datetime in excel.
"SB" <othellomy@.yahoo.com> wrote in message
news:1186485944.181307.110770@.w3g2000hsg.googlegroups.com...
> On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
> You should change the source data type to datetime or use text for
> both.
>|||On Aug 8, 3:51 am, "Johnfli" <j...@.ivhs.us> wrote:
> it's a text file.
> Before I export it to a text file, I have it formated as datetime in excel
.
> "SB" <othell...@.yahoo.com> wrote in message
> news:1186485944.181307.110770@.w3g2000hsg.googlegroups.com...
>
>
>
>
>
>
> - Show quoted text -
Hi,
I think it be easier if you import the text file AS IS that is all
columns as text (including the column with datetime) you can call it
Excel_to_text_TEMP. Once you have this table imported in the server
you can populate your main table from this temp table and use a
conversion function for datetime etc. HTH.|||I do intailly load it into a tmp table, as after its in teh temps table, I
have it go and only copy new original records into the main table, I also
have it update exsisting records. so with that said...
How do I convert it to datetime as it goes from the tmp table to teh main
table?
I am not an sql master or anythign, heck, i'm not ever a sql novice lol
so please have your example as clear as possible..
THANK YOU
"SB" <othellomy@.yahoo.com> wrote in message
news:1186545477.061884.9860@.19g2000hsx.googlegroups.com...
> On Aug 8, 3:51 am, "Johnfli" <j...@.ivhs.us> wrote:
> Hi,
> I think it be easier if you import the text file AS IS that is all
> columns as text (including the column with datetime) you can call it
> Excel_to_text_TEMP. Once you have this table imported in the server
> you can populate your main table from this temp table and use a
> conversion function for datetime etc. HTH.
>|||On Aug 8, 10:06 pm, "Johnfli" <j...@.ivhs.us> wrote:
> I do intailly load it into a tmp table, as after its in teh temps table, I
> have it go and only copy new original records into the main table, I also
> have it update exsisting records. so with that said...
> How do I convert it to datetime as it goes from the tmp table to teh main
> table?
> I am not an sql master or anythign, heck, i'm not ever a sql novice lol
> so please have your example as clear as possible..
> THANK YOU
> "SB" <othell...@.yahoo.com> wrote in message
> news:1186545477.061884.9860@.19g2000hsx.googlegroups.com...
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -
Hi,
Then you should drop the TEMP table and re-create it where all columns
should be varchar(255) or varchar(1000) etc. Then once the temp table
is loaded you should run a query such as (preferably in a sored
procedure, see Books online for syntax):
insert Excel_To_Text (
column1,
column2,
etc...,
date_Column1,
etc...)
select column1,
column2,
etc...,
convert(datetime,Date_Column1),
etc...
from Excel_To_Text_TEMP
Let me know if you have questions. Regards,
SB|||SB <othellomy@.yahoo.com> wrote in
news:1186631817.654696.162750@.19g2000hsx.googlegroups.com:
> On Aug 8, 10:06 pm, "Johnfli" <j...@.ivhs.us> wrote:
> Hi,
> Then you should drop the TEMP table and re-create it where all columns
> should be varchar(255) or varchar(1000) etc. Then once the temp table
> is loaded you should run a query such as (preferably in a sored
> procedure, see Books online for syntax):
> insert Excel_To_Text (
> column1,
> column2,
> etc...,
> date_Column1,
> etc...)
> select column1,
> column2,
> etc...,
> convert(datetime,Date_Column1),
> etc...
> from Excel_To_Text_TEMP
> Let me know if you have questions. Regards,
> SB
You might eliminate the text file and instead:
SELECT F1 AS [Col1], ... CAST(Fn AS datetime) AS [DateCol], ...
INTO [DestinationTable]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8. 0;HDR=YES;Database=full_path_to\filename
.xls',
'SELECT * FROM [SheetName$]')
Use the Microsoft.ACE.OLEDB.12.0 provider if you don't have Jet or if the
Excel version is 2007 (and, for Excel 2007, change Excel 8.0 to Excel
12.0).
You will probably find this a little tricky to get working (I surely
did!) so build up from a simple import, e.g. of a single integer column.
reading a txt file
On of the fileds in the txt file has a date 08/06/2007 (for example)
I need to read that into my field in my table that is set as datetime.
Is there somethign special that need to get done? When I try, i get teh
following error:
Conversion invalid for datatypes on column pair 1 (source column
'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
> I import data by omporting a txt file that is tab delimited.
> On of the fileds in the txt file has a date 08/06/2007 (for example)
> I need to read that into my field in my table that is set as datetime.
> Is there somethign special that need to get done? When I try, i get teh
> following error:
> Conversion invalid for datatypes on column pair 1 (source column
> 'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)
You should change the source data type to datetime or use text for
both.|||it's a text file.
Before I export it to a text file, I have it formated as datetime in excel.
"SB" <othellomy@.yahoo.com> wrote in message
news:1186485944.181307.110770@.w3g2000hsg.googlegroups.com...
> On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
>> I import data by omporting a txt file that is tab delimited.
>> On of the fileds in the txt file has a date 08/06/2007 (for example)
>> I need to read that into my field in my table that is set as datetime.
>> Is there somethign special that need to get done? When I try, i get teh
>> following error:
>> Conversion invalid for datatypes on column pair 1 (source column
>> 'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)
> You should change the source data type to datetime or use text for
> both.
>|||On Aug 8, 3:51 am, "Johnfli" <j...@.ivhs.us> wrote:
> it's a text file.
> Before I export it to a text file, I have it formated as datetime in excel.
> "SB" <othell...@.yahoo.com> wrote in message
> news:1186485944.181307.110770@.w3g2000hsg.googlegroups.com...
>
> > On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
> >> I import data by omporting a txt file that is tab delimited.
> >> On of the fileds in the txt file has a date 08/06/2007 (for example)
> >> I need to read that into my field in my table that is set as datetime.
> >> Is there somethign special that need to get done? When I try, i get teh
> >> following error:
> >> Conversion invalid for datatypes on column pair 1 (source column
> >> 'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)
> > You should change the source data type to datetime or use text for
> > both.- Hide quoted text -
> - Show quoted text -
Hi,
I think it be easier if you import the text file AS IS that is all
columns as text (including the column with datetime) you can call it
Excel_to_text_TEMP. Once you have this table imported in the server
you can populate your main table from this temp table and use a
conversion function for datetime etc. HTH.|||I do intailly load it into a tmp table, as after its in teh temps table, I
have it go and only copy new original records into the main table, I also
have it update exsisting records. so with that said...
How do I convert it to datetime as it goes from the tmp table to teh main
table?
I am not an sql master or anythign, heck, i'm not ever a sql novice lol
so please have your example as clear as possible..
THANK YOU
"SB" <othellomy@.yahoo.com> wrote in message
news:1186545477.061884.9860@.19g2000hsx.googlegroups.com...
> On Aug 8, 3:51 am, "Johnfli" <j...@.ivhs.us> wrote:
>> it's a text file.
>> Before I export it to a text file, I have it formated as datetime in
>> excel.
>> "SB" <othell...@.yahoo.com> wrote in message
>> news:1186485944.181307.110770@.w3g2000hsg.googlegroups.com...
>>
>> > On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
>> >> I import data by omporting a txt file that is tab delimited.
>> >> On of the fileds in the txt file has a date 08/06/2007 (for
>> >> example)
>> >> I need to read that into my field in my table that is set as datetime.
>> >> Is there somethign special that need to get done? When I try, i get
>> >> teh
>> >> following error:
>> >> Conversion invalid for datatypes on column pair 1 (source column
>> >> 'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)
>> > You should change the source data type to datetime or use text for
>> > both.- Hide quoted text -
>> - Show quoted text -
> Hi,
> I think it be easier if you import the text file AS IS that is all
> columns as text (including the column with datetime) you can call it
> Excel_to_text_TEMP. Once you have this table imported in the server
> you can populate your main table from this temp table and use a
> conversion function for datetime etc. HTH.
>|||On Aug 8, 10:06 pm, "Johnfli" <j...@.ivhs.us> wrote:
> I do intailly load it into a tmp table, as after its in teh temps table, I
> have it go and only copy new original records into the main table, I also
> have it update exsisting records. so with that said...
> How do I convert it to datetime as it goes from the tmp table to teh main
> table?
> I am not an sql master or anythign, heck, i'm not ever a sql novice lol
> so please have your example as clear as possible..
> THANK YOU
> "SB" <othell...@.yahoo.com> wrote in message
> news:1186545477.061884.9860@.19g2000hsx.googlegroups.com...
>
> > On Aug 8, 3:51 am, "Johnfli" <j...@.ivhs.us> wrote:
> >> it's a text file.
> >> Before I export it to a text file, I have it formated as datetime in
> >> excel.
> >> "SB" <othell...@.yahoo.com> wrote in message
> >>news:1186485944.181307.110770@.w3g2000hsg.googlegroups.com...
> >> > On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
> >> >> I import data by omporting a txt file that is tab delimited.
> >> >> On of the fileds in the txt file has a date 08/06/2007 (for
> >> >> example)
> >> >> I need to read that into my field in my table that is set as datetime.
> >> >> Is there somethign special that need to get done? When I try, i get
> >> >> teh
> >> >> following error:
> >> >> Conversion invalid for datatypes on column pair 1 (source column
> >> >> 'DoRecd'(dbstype_str), destination column 'doRecd'(DBTYPE_DBtimestamp)
> >> > You should change the source data type to datetime or use text for
> >> > both.- Hide quoted text -
> >> - Show quoted text -
> > Hi,
> > I think it be easier if you import the text file AS IS that is all
> > columns as text (including the column with datetime) you can call it
> > Excel_to_text_TEMP. Once you have this table imported in the server
> > you can populate your main table from this temp table and use a
> > conversion function for datetime etc. HTH.- Hide quoted text -
> - Show quoted text -
Hi,
Then you should drop the TEMP table and re-create it where all columns
should be varchar(255) or varchar(1000) etc. Then once the temp table
is loaded you should run a query such as (preferably in a sored
procedure, see Books online for syntax):
insert Excel_To_Text (
column1,
column2,
etc...,
date_Column1,
etc...)
select column1,
column2,
etc...,
convert(datetime,Date_Column1),
etc...
from Excel_To_Text_TEMP
Let me know if you have questions. Regards,
SB|||SB <othellomy@.yahoo.com> wrote in
news:1186631817.654696.162750@.19g2000hsx.googlegroups.com:
> On Aug 8, 10:06 pm, "Johnfli" <j...@.ivhs.us> wrote:
>> I do intailly load it into a tmp table, as after its in teh temps
>> table, I have it go and only copy new original records into the main
>> table, I also have it update exsisting records. so with that
>> said...
>> How do I convert it to datetime as it goes from the tmp table to teh
>> main table?
>> I am not an sql master or anythign, heck, i'm not ever a sql novice
>> lol
>> so please have your example as clear as possible..
>> THANK YOU
>> "SB" <othell...@.yahoo.com> wrote in message
>> news:1186545477.061884.9860@.19g2000hsx.googlegroups.com...
>>
>> > On Aug 8, 3:51 am, "Johnfli" <j...@.ivhs.us> wrote:
>> >> it's a text file.
>> >> Before I export it to a text file, I have it formated as datetime
>> >> in excel.
>> >> "SB" <othell...@.yahoo.com> wrote in message
>> >>news:1186485944.181307.110770@.w3g2000hsg.googlegroups.com...
>> >> > On Aug 6, 11:14 pm, "Johnfli" <j...@.ivhs.us> wrote:
>> >> >> I import data by omporting a txt file that is tab delimited.
>> >> >> On of the fileds in the txt file has a date 08/06/2007 (for
>> >> >> example)
>> >> >> I need to read that into my field in my table that is set as
>> >> >> datetime.
>> >> >> Is there somethign special that need to get done? When I try,
>> >> >> i get teh
>> >> >> following error:
>> >> >> Conversion invalid for datatypes on column pair 1 (source
>> >> >> column 'DoRecd'(dbstype_str), destination column
>> >> >> 'doRecd'(DBTYPE_DBtimestamp)
>> >> > You should change the source data type to datetime or use text
>> >> > for both.- Hide quoted text -
>> >> - Show quoted text -
>> > Hi,
>> > I think it be easier if you import the text file AS IS that is all
>> > columns as text (including the column with datetime) you can call
>> > it Excel_to_text_TEMP. Once you have this table imported in the
>> > server you can populate your main table from this temp table and
>> > use a conversion function for datetime etc. HTH.- Hide quoted text
>> > -
>> - Show quoted text -
> Hi,
> Then you should drop the TEMP table and re-create it where all columns
> should be varchar(255) or varchar(1000) etc. Then once the temp table
> is loaded you should run a query such as (preferably in a sored
> procedure, see Books online for syntax):
> insert Excel_To_Text (
> column1,
> column2,
> etc...,
> date_Column1,
> etc...)
> select column1,
> column2,
> etc...,
> convert(datetime,Date_Column1),
> etc...
> from Excel_To_Text_TEMP
> Let me know if you have questions. Regards,
> SB
You might eliminate the text file and instead:
SELECT F1 AS [Col1], ... CAST(Fn AS datetime) AS [DateCol], ...
INTO [DestinationTable]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;HDR=YES;Database=full_path_to\filename.xls',
'SELECT * FROM [SheetName$]')
Use the Microsoft.ACE.OLEDB.12.0 provider if you don't have Jet or if the
Excel version is 2007 (and, for Excel 2007, change Excel 8.0 to Excel
12.0).
You will probably find this a little tricky to get working (I surely
did!) so build up from a simple import, e.g. of a single integer column.sql
reader headers of table
date, leader_count, employee_count, manager_count
10/14/2005, 4 ,5 ,5
Any idea how I can almost transpose the table to create a table that looks
like:
date, type, count
10/14/2005, leader, 4
10/15/2005, employee, 5
Thanks for any suggestions.
what do you mean transpose, how about using a view ?
"AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
>I have a table that has :
> date, leader_count, employee_count, manager_count
> 10/14/2005, 4 ,5 ,5
> Any idea how I can almost transpose the table to create a table that looks
> like:
> date, type, count
> 10/14/2005, leader, 4
> 10/15/2005, employee, 5
> Thanks for any suggestions.
|||Or where you looking for something like this ?
--
DROP TABLE Table1
CREATE TABLE Table1
(
[date] datetime,
leader_count int,
employee_count int,
manager_count int
)
INSERT INTO Table1 VALUES('10/14/2005', 4 ,5 ,5)
SELECT * FROM Table1
DROP TABLE NewTable
CREATE TABLE NewTable
(
[date] datetime,
Type char(10),
[count] int
)
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Leader',leader_count FROM Table1
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Employee',employee_count FROM Table1
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Manager',manager_count FROM Table1
Go
SELECT * FROM NewTable
but try not to use so many reserved words
"David J. Cartwright" <davidcartwright@.hotmail.com> wrote in message
news:eliQgmO$FHA.140@.TK2MSFTNGP12.phx.gbl...
> what do you mean transpose, how about using a view ?
> "AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
> news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
>
|||PERFECT! THANK YOU VERY MUCH.
"David J. Cartwright" wrote:
> Or where you looking for something like this ?
> --
> --
> DROP TABLE Table1
> CREATE TABLE Table1
> (
> [date] datetime,
> leader_count int,
> employee_count int,
> manager_count int
> )
> INSERT INTO Table1 VALUES('10/14/2005', 4 ,5 ,5)
> SELECT * FROM Table1
> DROP TABLE NewTable
> CREATE TABLE NewTable
> (
> [date] datetime,
> Type char(10),
> [count] int
> )
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Leader',leader_count FROM Table1
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Employee',employee_count FROM Table1
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Manager',manager_count FROM Table1
> Go
> SELECT * FROM NewTable
> --
> but try not to use so many reserved words
> "David J. Cartwright" <davidcartwright@.hotmail.com> wrote in message
> news:eliQgmO$FHA.140@.TK2MSFTNGP12.phx.gbl...
>
>
reader headers of table
date, leader_count, employee_count, manager_count
10/14/2005, 4 ,5 ,5
Any idea how I can almost transpose the table to create a table that looks
like:
date, type, count
10/14/2005, leader, 4
10/15/2005, employee, 5
Thanks for any suggestions.what do you mean transpose, how about using a view ?
"AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
>I have a table that has :
> date, leader_count, employee_count, manager_count
> 10/14/2005, 4 ,5 ,5
> Any idea how I can almost transpose the table to create a table that looks
> like:
> date, type, count
> 10/14/2005, leader, 4
> 10/15/2005, employee, 5
> Thanks for any suggestions.|||Or where you looking for something like this ?
--
DROP TABLE Table1
CREATE TABLE Table1
(
[date] datetime,
leader_count int,
employee_count int,
manager_count int
)
INSERT INTO Table1 VALUES('10/14/2005', 4 ,5 ,5)
SELECT * FROM Table1
DROP TABLE NewTable
CREATE TABLE NewTable
(
[date] datetime,
Type char(10),
[count] int
)
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Leader',leader_count FROM Table1
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Employee',employee_count FROM Table1
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Manager',manager_count FROM Table1
Go
SELECT * FROM NewTable
--
but try not to use so many reserved words
"David J. Cartwright" <davidcartwright@.hotmail.com> wrote in message
news:eliQgmO$FHA.140@.TK2MSFTNGP12.phx.gbl...
> what do you mean transpose, how about using a view ?
> "AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
> news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
>|||PERFECT! THANK YOU VERY MUCH.
"David J. Cartwright" wrote:
> Or where you looking for something like this ?
> --
> --
> DROP TABLE Table1
> CREATE TABLE Table1
> (
> [date] datetime,
> leader_count int,
> employee_count int,
> manager_count int
> )
> INSERT INTO Table1 VALUES('10/14/2005', 4 ,5 ,5)
> SELECT * FROM Table1
> DROP TABLE NewTable
> CREATE TABLE NewTable
> (
> [date] datetime,
> Type char(10),
> [count] int
> )
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Leader',leader_count FROM Table1
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Employee',employee_count FROM Table1
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Manager',manager_count FROM Table1
> Go
> SELECT * FROM NewTable
> --
> but try not to use so many reserved words
> "David J. Cartwright" <davidcartwright@.hotmail.com> wrote in message
> news:eliQgmO$FHA.140@.TK2MSFTNGP12.phx.gbl...
>
>
reader headers of table
date, leader_count, employee_count, manager_count
10/14/2005, 4 ,5 ,5
Any idea how I can almost transpose the table to create a table that looks
like:
date, type, count
10/14/2005, leader, 4
10/15/2005, employee, 5
Thanks for any suggestions.what do you mean transpose, how about using a view ?
"AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
>I have a table that has :
> date, leader_count, employee_count, manager_count
> 10/14/2005, 4 ,5 ,5
> Any idea how I can almost transpose the table to create a table that looks
> like:
> date, type, count
> 10/14/2005, leader, 4
> 10/15/2005, employee, 5
> Thanks for any suggestions.|||Or where you looking for something like this ?
--
--
DROP TABLE Table1
CREATE TABLE Table1
(
[date] datetime,
leader_count int,
employee_count int,
manager_count int
)
INSERT INTO Table1 VALUES('10/14/2005', 4 ,5 ,5)
SELECT * FROM Table1
DROP TABLE NewTable
CREATE TABLE NewTable
(
[date] datetime,
Type char(10),
[count] int
)
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Leader',leader_count FROM Table1
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Employee',employee_count FROM Table1
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Manager',manager_count FROM Table1
Go
SELECT * FROM NewTable
--
but try not to use so many reserved words
"David J. Cartwright" <davidcartwright@.hotmail.com> wrote in message
news:eliQgmO$FHA.140@.TK2MSFTNGP12.phx.gbl...
> what do you mean transpose, how about using a view ?
> "AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
> news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
>>I have a table that has :
>> date, leader_count, employee_count, manager_count
>> 10/14/2005, 4 ,5 ,5
>> Any idea how I can almost transpose the table to create a table that
>> looks
>> like:
>> date, type, count
>> 10/14/2005, leader, 4
>> 10/15/2005, employee, 5
>> Thanks for any suggestions.
>|||PERFECT! THANK YOU VERY MUCH.
"David J. Cartwright" wrote:
> Or where you looking for something like this ?
> --
> --
> DROP TABLE Table1
> CREATE TABLE Table1
> (
> [date] datetime,
> leader_count int,
> employee_count int,
> manager_count int
> )
> INSERT INTO Table1 VALUES('10/14/2005', 4 ,5 ,5)
> SELECT * FROM Table1
> DROP TABLE NewTable
> CREATE TABLE NewTable
> (
> [date] datetime,
> Type char(10),
> [count] int
> )
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Leader',leader_count FROM Table1
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Employee',employee_count FROM Table1
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Manager',manager_count FROM Table1
> Go
> SELECT * FROM NewTable
> --
> but try not to use so many reserved words
> "David J. Cartwright" <davidcartwright@.hotmail.com> wrote in message
> news:eliQgmO$FHA.140@.TK2MSFTNGP12.phx.gbl...
> > what do you mean transpose, how about using a view ?
> >
> > "AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
> > news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
> >>I have a table that has :
> >>
> >> date, leader_count, employee_count, manager_count
> >> 10/14/2005, 4 ,5 ,5
> >>
> >> Any idea how I can almost transpose the table to create a table that
> >> looks
> >> like:
> >>
> >> date, type, count
> >> 10/14/2005, leader, 4
> >> 10/15/2005, employee, 5
> >>
> >> Thanks for any suggestions.
> >
> >
>
>
Monday, March 26, 2012
Read portion of file using SSIS
Is it possible to read a portion of a file using SSIS. The file format is:
date: 17 Apr 07
input file: input1.unl
output file: output.unl
table1-column1 table1-column2 ..................
123 23445
235 33367
table2-column1 table2-column2 ......................
234 454
444 89877
i have to read only the table1. i have written a routine in c# that reads only table1 but that is too slow. Is there any efficient solution?
It looks like your table1 and table2 have the same format. Is that correct?
Do your rows have some identifier that tells from which table they are coming? If yes, you might be able to load everything and then filter out the rows you need.
HTH.
|||No the tables have different format. Rows have no identifier but there are two line breaks between the two tables. Can I read only that portion of file.|||No, the flat file parser will not be able to do that.
You might be able to use the Script Task to break your files before they are used by Flat File source.
Friday, March 23, 2012
Read file info via Transact SQL....
Any ideas how I could go about getting a file's "Created" date/time into a
datetime variable using T-SQL? I'm thinking along the lines of using the
results of a call to xp_cmdshell but as to what command I should call...
well...
Any help would be appreciated!Sure you can use any DOS command via xp_cmdshell. Here is a rough example
of reading datetimes.
CREATE TABLE #dirlist (FName VARCHAR(1000))
-- Insert the results of the dir cmd into a table so we can scan it
INSERT INTO #dirlist (FName)
exec master..xp_cmdshell 'dir /OD C:\Backups\*.trn'
-- Remove the garbage
DELETE #dirlist WHERE
SUBSTRING(FName,1,2) < '00' OR
SUBSTRING(FName,1,2) > '99' OR
FName IS NULL
SELECT SUBSTRING(FName,40,40) AS FName
FROM #dirlist
WHERE CAST(SUBSTRING(FName,1,20) AS DATETIME) < @.DelDate
AND SUBSTRING(FName,40,40) LIKE '%.TRN'
Andrew J. Kelly SQL MVP
"len" <len@.discussions.microsoft.com> wrote in message
news:74125E9D-6E97-46FE-855C-CA2913135FE3@.microsoft.com...
> Hi there.
> Any ideas how I could go about getting a file's "Created" date/time into a
> datetime variable using T-SQL? I'm thinking along the lines of using the
> results of a call to xp_cmdshell but as to what command I should call...
> well...
> Any help would be appreciated!|||Rather than placing this functionality in a stored procedure, consider a DTS
package and VBScript task.
http://msdn.microsoft.com/library/d...
flow_0793.asp
http://www.sqldts.com/?246
http://msdn.microsoft.com/library/d...efc4b9f49c7.asp
"len" <len@.discussions.microsoft.com> wrote in message
news:74125E9D-6E97-46FE-855C-CA2913135FE3@.microsoft.com...
> Hi there.
> Any ideas how I could go about getting a file's "Created" date/time into a
> datetime variable using T-SQL? I'm thinking along the lines of using the
> results of a call to xp_cmdshell but as to what command I should call...
> well...
> Any help would be appreciated!sql
Tuesday, March 20, 2012
Re: help please
I have 3 column: date, time, stocks name, price
I have 2 questions:
1. what is the command (or query languange) to get the
the first and/or last observations for any given day (i know it can be done in
aggregate query, in Ms acces but can it be done in SQL server query as well?)?
e.g. I want to get the first and last price of the day for any particular stocks
2. how to calculate return with the following formula:
return=log P(t)-log P(t-1), where P(t) is price at
time t say 10 am and P(t-1) is price at one period
previous t say 9 am?
Regards
CharlyThe min and max functions will tell you the price ranges
eg select max(pricecolumn) from tablename where date='20040517'
select min(pricecolumn) from tablename where date='20040517'
If you want to be more selective look at the date/time setting you are using in your data and tailor the where command to select at that particular time
eg where date='2003-02-28 10:00:00.000'
Look at books online for the log function, and use selective where clauses for the times, ie where date='2004-05-17 10:00:00.000'|||select max(pricecolumn) from tablename where date='20040517'
broup by [stocks name]