As known SQL Server 2000 need some dynamic sqls to convert rows to columns or vice versa. PIVOT and UNPIVOT relational operator did the job of converting rows to columns and columns to rows respectively.we can transpose values from rows to columns in sql server 2005 using PIVOT relational operator,
Ex Of Transpose:
create table #t (
id int identity(1,1),
AJAN int,
AFEB int,
AMAR int,
FJAN int,
FFEB int,
FMAR int
)
insert into #t (AJAN,AFEB,AMAR,FJAN,FFEB,FMAR) values (1,2,3,4,5,6)
insert into #t (AJAN,AFEB,AMAR,FJAN,FFEB,FMAR) values (11,12,13,14,15,16)
select * from #t
select
id,
'A'+c as amonth,
sum(case when c1='A' then val else 0 end) as aval,
'F'+c as fmonth,
sum(case when c1='F' then val else 0 end) as fval
from (
select id, val, substring(col,1,1) as c1, substring(col,2,3) as c
from #t
unpivot (val for col in (AJAN,AFEB,AMAR,FJAN,FFEB,FMAR)) up
) t
group by id,c
order by id,c
Wednesday, August 4, 2010
SQL Server Data Transformation Services (DTS)
INTRODUCTION:
Microsoft released Data Transformation Services (DTS) along with SQL Server 7.0. A very powerful, easy to use, graphical tool for importing, exporting and transforming data, which is only available as a costly add-on in other RDBMS products like Oracle. Prior to SQL Server 7.0, all we had was BCP, which is powerful indeed, but not as friendly and functionally rich as DTS. DTS was made robust and dramatically improved with the release of SQL Server 2000, as more and more DBAs and developers started using DTS for building various data loading and transformation solutions. It wouldn't be an exaggeration to say that DTS is one of the most popular ETL (Extract, Transform and Load) tools currently in use. Not bad for a tool that's been around for just about four years.
INTRODUCTION:
If you need to get data into or out of SQL Server, either as a one-off or on a regular basis, there are several ways to achieve this. However in many situations the best solution is to use the excellent DTS (Data Transformation Services) application included with SQL Server 2000 or the replacement SQL Server Integration Services (SSIS) in SQL Server 2005.
DTS/SSIS are large and complex applications, however they are also extremely powerful and consequently we use them for most data conversion tasks, even when neither the source nor the destination is SQL Server!
In addition to transferring data they can also be used to transform or modify the data during the import process. For example a single import file may be used to update multiple tables within the database.
Examples
Examples of some of the tasks that can be undertaken using DTS/SSIS include....
Importing .csv data files from a separate computer.
Importing data from existing Access database.
Exporting SQL data to an Excel spreadsheet.
Exporting data to csv files.
Copy data from one SQL Server to another.
Specific Example
One use to which we have employed DTS for was for importing new and updated works orders from a third party computer system. Data from the other computer was placed in .csv files at a predefined location on the network. We wrote a DTS system that :
Validated the folder structure to ensure that the expected directories were present.
Checked the validated folder to see if any new files were ready for importing.
Located the first csv file of Address data to import.
Validated the incoming raw Address data and imported it into a temporary table.
Processed all address updates, modifying existing data in the main Address table.
Processed all additions, adding new records to the same Address table.
Located the first csv file of Works Order data to import.
Validated the incoming raw Works Order data and imported it into a temporary table.
Process all works order updates, modifying existing data in the main Works Order table.
Process all additions, adding new records to the same Works Order table.
Re-named the processed files to include the date that they were processed on.
Moved the re-named csv files to a separate archive directory.
Cycle back to stage 2 to see if there are any other files to import.
Create a csv file of updated Works Orders with their revised statuses.
Create a csv file of Invoices for completed Works Orders.
Transferred the created csv files using FTP to the client's UNIX server.
Microsoft released Data Transformation Services (DTS) along with SQL Server 7.0. A very powerful, easy to use, graphical tool for importing, exporting and transforming data, which is only available as a costly add-on in other RDBMS products like Oracle. Prior to SQL Server 7.0, all we had was BCP, which is powerful indeed, but not as friendly and functionally rich as DTS. DTS was made robust and dramatically improved with the release of SQL Server 2000, as more and more DBAs and developers started using DTS for building various data loading and transformation solutions. It wouldn't be an exaggeration to say that DTS is one of the most popular ETL (Extract, Transform and Load) tools currently in use. Not bad for a tool that's been around for just about four years.
INTRODUCTION:
If you need to get data into or out of SQL Server, either as a one-off or on a regular basis, there are several ways to achieve this. However in many situations the best solution is to use the excellent DTS (Data Transformation Services) application included with SQL Server 2000 or the replacement SQL Server Integration Services (SSIS) in SQL Server 2005.
DTS/SSIS are large and complex applications, however they are also extremely powerful and consequently we use them for most data conversion tasks, even when neither the source nor the destination is SQL Server!
In addition to transferring data they can also be used to transform or modify the data during the import process. For example a single import file may be used to update multiple tables within the database.
Examples
Examples of some of the tasks that can be undertaken using DTS/SSIS include....
Importing .csv data files from a separate computer.
Importing data from existing Access database.
Exporting SQL data to an Excel spreadsheet.
Exporting data to csv files.
Copy data from one SQL Server to another.
Specific Example
One use to which we have employed DTS for was for importing new and updated works orders from a third party computer system. Data from the other computer was placed in .csv files at a predefined location on the network. We wrote a DTS system that :
Validated the folder structure to ensure that the expected directories were present.
Checked the validated folder to see if any new files were ready for importing.
Located the first csv file of Address data to import.
Validated the incoming raw Address data and imported it into a temporary table.
Processed all address updates, modifying existing data in the main Address table.
Processed all additions, adding new records to the same Address table.
Located the first csv file of Works Order data to import.
Validated the incoming raw Works Order data and imported it into a temporary table.
Process all works order updates, modifying existing data in the main Works Order table.
Process all additions, adding new records to the same Works Order table.
Re-named the processed files to include the date that they were processed on.
Moved the re-named csv files to a separate archive directory.
Cycle back to stage 2 to see if there are any other files to import.
Create a csv file of updated Works Orders with their revised statuses.
Create a csv file of Invoices for completed Works Orders.
Transferred the created csv files using FTP to the client's UNIX server.
Session Expire and Redirect to login Page specify after Some Time Period
Context.Response.AppendHeader("Refresh",
Convert.ToString(Session.Timeout = 10) + "; URL=Login.aspx" );
Convert.ToString(Session.Timeout = 10) + "; URL=Login.aspx" );
Subscribe to:
Posts (Atom)