Learn SQL and database management at SQLYoga for articles, tutorials, and tips to improve your skills and streamline data operations. Join our community!
June 9, 2010
My First article on SQL SERVER Central about Access variables values from Trigger
I would recommend all SQL lovers, to subscribe to the news letter of SQL SERVER CENTRAL, which consists of tips and tricks, useful in real world applications.
Please feel free to contact me at tejasnshah.it@gmail.com for any MS SQL SERVER query/help.
PS: Hope you all will read more and more articles from me, in forthcoming newsletters ;)
Enjoy Reading!!
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
April 6, 2010
SQL SERVER SSIS: Get File Name with Flat File Source, Data Flow Component
| As I explained earlier about For Each Loop Container, which process each file from selected folder. There is a requirement to save File name along with record, so later on we can identify which record comes from which file. Let me explain it how to achieve with FileNameColumnName property of Flat File Connection to get it easily. 1. Setup Flat File Connection with CSV file, as mentioned Basic Example of Data Flow Task. 2. Right click on Flat File Source, and click on Show Advanced Editor: 3. Click on "Component Properties" and go to FileNameColumnName, Custom properties: 4. Setup FileNameColumnName value with desired column name. Let's say "File Name". Congratulations, This column is added to output list with actual filename of that connection. |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
March 7, 2010
SQL SERVER: Execute Stored Procedure when SQL SERVER is started
We have a requirements to execute Stored Procedure when SQL SERVER is started/restarted and we need to start some processes. I found that SQL SERVER provides a way to call Stored Procedure when SQL services are restarted.
SQL SERVER provides this SP: "sp_procoption", which is auto executed every time when SQL SERVER service has been started. I found this SP and it helps me to figure it out the solution for the request as following way.
Let me show you how to use it. Syntax to use SP:
EXEC SP_PROCOPTION
@ProcName = 'SPNAME',
@OptionName = 'startup',
@OptionValue = 'true/false OR on/off'
- @ProcName, should be Stored procedure name which should be executed when SQL SERVER is started. This stored procedure must be in "master" database.
- @OptionName, should be "startup" always.
- @OptionValue, this should be set up to execute this given sp or not. If it is "true/on", given sp will be execute every time when SQL SERVER is started. If it is "false/off", it will not.
That's it, I hope this is very clear to use this feature.
Reference : Tejas Shah (http://www.SQLYoga.com)
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
January 10, 2010
SQL SERVER: SSIS - Derived Column Data Flow Transformation
| As I explained earlier about Foreach Loop Container. One of regular reader of blog send me an email about one issue. Let me share that problem with all readers. With this example, Foreach Loop Container, What to do if we want to save file name along with each row, so we can come to know that which row is from which file ? This is very practical problem that we need to fix. To solve this, I come up with following solution. 1. I used "Derived Column", one of Data Flow Transformations in Data Flow Operations. 2. Configure Derived Column: As we have variable, FileName, as defined in, SQL SERVER: SSIS - Foreach Loop Container. Here I used that variable as a new column. By dragging that User variable to Expression. By default it assign UNICODE STRING DataType to this new column. We need to change it by: A. Right click on "Derived Column", Go to Show Advanced Editor B. Set DataType to String as: 3. That's it. Now just add it to Destination Column Mapping with your Database column. Let me know your suggestions. |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
December 20, 2009
SQL SERVER: Presentation at Ahmedabad User Group Meeting
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
December 7, 2009
SQL SERVER: SSIS - Transfer Jobs Task
The Transfer Jobs task can be configured to transfer all jobs, or only specified jobs. You can also indicate whether the transferred jobs are enabled at the destination.
The jobs to be transferred may already exist on the destination. The Transfer Jobs task can be configured to handle existing jobs in the following ways:
- Overwrite existing jobs.
- Fail the task when duplicate jobs exist.
- Skip duplicate jobs.
1. Select and Drag, Transfer Jobs Task, from Container Flow Items to designer surface.
2. To configure a task, Right click on Transfer Jobs Task, which we dragged to Design surface. Click on "Edit.", you will get page as:
3. SSIS Transfer Jobs Task - General : Here we need to assign unique name to this task and also we can specify brief description, so we will get idea why we need to design this task.
4. SSIS Transfer Jobs Task - Jobs : Jobs page of the Transfer Jobs Task Editor dialog box is required to specify properties for copying one or more SQL Server Agent jobs from one instance of SQL Server to another.
Let's take a view how each properties are used.
SourceConnection: Select a SMO connection manager in the list, or click <New connection...> to create a new connection to the source server
DestinationConnection: Select a SMO connection manager in the list, or click <New connection...> to create a new connection to the destination server.
JobsList: Click the browse button (.) to select the jobs to copy. At least one job must be selected.
FailTask: If job of the same name already exists on the Destination Server then task will fail.
Overwrite: If job of the same name already exists on the Destination Server then task will overwrite the job.
Skip: If job of the same name already exists on the Destination Server then task will skip that job.
TRUE: Enable jobs on destination server.
FALSE: Disable jobs on destination server.
5. SSIS Transfer Jobs Task - Expressions: Click the ellipsis to open the Property Expressions Editor dialog box.
Property expressions update the values of properties when the package is run. The expressions are evaluated and their results are used instead of the values to which you set the properties when you configured the package and package objects. The expressions can include variables and the functions and operators that the expression language provides.
Now let's run task, by right click on task and click on Execute Task, as shown in following figure. You can either Execute Package by right click on Package name, from Solution Explorer.
Once you run this then all/selected jobs will be transferred to destination server as per given criteria.
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
December 3, 2009
SQL SERVER: How to Read Excel file by TSQL
| Many times developers asked that, they want to import data from Excel file. We can do this by many ways with SQL SERVER. 1. We can use SSIS package 2. Import/Export Wizard 3. T-SQL Today, I am going to explain, How to import data from Excel file by TSQL. To import Excel file by TSQL, we need to do following: 1. Put Excel file on server, means we need to put files on server, if we are accessing it from local. 2. Write following TSQL, to read data from excel file SELECT Name, Email, PhoneFROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\SQLYoga.xls', [SQL$]) NOTE: Here, Excel file is on "C:\" named "SQLYoga.xls", and I am reading sheet "SQL" from this excel file If you want to insert excel data into table, INSERT INTO [Info]SELECT Name, Email, PhoneFROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\test\SQLYoga.xls', [SQL$]) That's it. |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
December 2, 2009
SQL SERVER: How to remove cursor
| Many times developer ask me that How can they remove Cursor? They need to increase Query Performance, that's why they need to remove SQL SERVER Cursor and find the alternate way to accomplish the same. Please find this code to remove cursor with Table variable: --declare table to keep records to be processedDECLARE @Table AS TABLE(AutoID INT IDENTITY, Column1 VARCHAR(100), Column2 VARCHAR(100))--populate table variable with data that we want to processINSERT INTO @Table(Column1, Column2)SELECT Column1, Column2FROM <Table>WHERE <Conditions>--declare variables to process each recordDECLARE @inc INT, @cnt INT--Assign increment counterSELECT @inc = 1--Get Number of records to be processedSELECT @cnt = COUNT(*)FROM @TableWHILE @inc <= @cnt BEGIN--As we have AutoID declared as IDENTITY, it always get only one record.--Get values in Variable and process it as you want.SELECT @Column1 = Column1,@Column2 = Column2FROM @TableWHERE AutoID = @inc--do your calculation here........--Select next recordSET @inc = @inc = 1END By this way, we can remove CURSOR by Table variable. It is quite easy to implement. One more benefit is: It will process one record at a time, so it locks only that record at a time. Let me know if you have any questions. |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
November 28, 2009
SQL SERVER SSIS: How to assign Connection from variable
| Last Article, SSIS - Foreach Loop Container, We need to assign dynamic connection to file connection, so SSIS For each loop Task can take each file from folder. Lets configure File connection from variable for SSIS - Foreach Loop Container. What we need to do is, we need to process each file from folder, so we need to assign value from variable to File connection, so SSIS Task will read that file and process that file. To assign FileConnection dynamicaly we need to do following. 1. Right click on File Connection, click Properties. 2. Set DelayValidation = "False", as we need to assign connection dynamically. 3. Click on "Expression", and enter variable name, which we used in SSIS - Foreach Loop Container. That's it. It will assign connection from variable and process that file. Let me know if you have any question for the same. |
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS
November 9, 2009
SQL SERVER: SSIS - Foreach Loop Container
- Foreach File Enumerator: Enumerate files
- Foreach Item Enumerator: Enumerate values in an item
- Foreach ADO Enumerator: Enumerate tables or rows in tables
- Foreach ADO.NET Schema Rowset Enumerator: Enumerate a schema
- Foreach From Variable Enumerator: Enumerate the value in a variable
- Foreach Nodelist Enumerator: Enumerate nodes in an XML document
- Foreach SMO Enumerator: Enumerate a SMO object
- Fully qualified: Select to retrieve the fully qualified path of file names.
- Name and extension: Select to retrieve the file names and their file name extensions.
- Name only: Select to retrieve only the file names.
18+ years of Hands-on Experience
MICROSOFT CERTIFIED PROFESSIONAL (Microsoft SQL Server)
Proficient in .NET C#
Hands on working experience on MS SQL, DBA, Performance Tuning, Power BI, SSIS, and SSRS