SELECT C2.NAME AS Data_Source_Name , C.NAME AS ReportName , C.Path AS ReportPath FROM ReportServer.dbo.DataSource AS DS INNER JOIN ReportServer.dbo.CATALOG AS C ON DS.ItemID = C.ItemID AND DS.Link IN ( SELECT ItemID FROM ReportServer.dbo.CATALOG WHERE Type = 5 ) --Type 5 identifies data sources FULL JOIN ReportServer.dbo.CATALOG C2 ON DS.Link = C2.ItemID WHERE C2.Type = 5 ORDER BY C2.NAME ASC , C.NAME ASC;
November 17, 2017
August 14, 2015
SQL Server: Use of Recursive Query with example
DECLARE @Images TABLE ( [ResourceID] [int] NOT NULL, [ChildOf] [int] NOT NULL, [ResourceName] [varchar](250) NOT NULL )
INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (5, 0, N'Mammal') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (6, 5, N'Carnivore') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (14, 6, N'Cannine') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (15, 14, N'Dog') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (16, 15, N'Dog1') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (17, 14, N'Monkey') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (18, 17, N'Monkey1') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (19, 16, N'dog1.01') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (21, 18, N'monkey1.02') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (23, 17, N'test') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (25, 17, N'Monkey 2') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (31, 0, N'Fish') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (32, 31, N'cartilaginous fish') INSERT @Images ([ResourceID], [ChildOf], [ResourceName]) VALUES (33, 32, N'dogfish')
;WITH images AS ( SELECT * ,ROW_NUMBER() OVER ( ORDER BY ResourceID ) AS RowID FROM @images ) ,cte AS ( SELECT 1 AS [Level] ,[ResourceID] ,[ResourceName] ,ChildOf ,cast(cast(RowID AS VARBINARY(4)) AS VARBINARY(max)) AS sort FROM images WHERE ChildOf = 0 --where [ResourceID] = 5 UNION ALL SELECT p.[Level] + 1 ,c.[ResourceID] ,c.[ResourceName] ,c.ChildOf ,cast(p.sort + cast(c.RowID AS VARBINARY(4)) AS VARBINARY(max)) FROM images c INNER JOIN cte p ON p.[ResourceID] = c.ChildOf --WHERE c.ChildOF=5 ) SELECT ResourceID ,ChildOf ,REPLICATE('.', ([Level] - 1) * 4) + [ResourceName] AS menu FROM cte ORDER BY sort
September 4, 2014
SQL SERVER: SSIS - Rename and move files from source folder to destination folder
With SSIS, most of the time we need to process all the files from the folder. Once file has been processed, we need to move the file to archive folder, so we should know that file has been processed and we have the file in archive folder. Here, We are going to process the files and then will move the file from source folder to archive folder by appending date and time to the filename, so we can use it for future reference. SSIS will do both of these things, Rename a file and move a file, with File System Task with operation “Rename file”. Let’s review how it works: 1. Add Variables:To configure Source folder and Archive Folder by variable
Here, we are adding Current Date time to the filename by expression as mentioned below.
3. Add For each Loop Container and set properties :Now, lets loop thru the folder and process each file from the folder by “For Each loop”. Here, we can setup the folder by Expressions->Directory use Expression @[User::SourceFolder]. We should also specify which type of files we are going to process, like “txt”, “csv” etc..by specifying the same in “Files”. We are fetching the file name with extension so that option needs to be selected as displayed in the following screenshot. ![]() We need to assign each file name to the variable, by Variable Mappings->set variable [User::FileName] and Index as 0 ![]() 4. Add File System Task:Add “File System Task” inside “For each Loop Container” ![]() 5. Set properties for File System Task:This is the place where we need to setup the operation, which will do our job. A. Configure SourceVariable B. Configure DestinationVariable C. Select operation: “Rename File”, which will rename the file and move it to the Archive Folder as we have specified in variable. ![]() 6. Run package and check ![]() With SSIS, it is much simple to process multiple files as mentioned above. Reference: Tejas Shah (www.SQLYoga.com) |
September 1, 2014
SQL SERVER: SSIS - Conditional Split Data Flow Transformation Task
Conditional Split transform use split the source row in easy to multiple groups in data flow and which Destination table populated. Lets review the same by reading a Sample text file and separate out the data in two groups. 1. Create sample text file: This text file is piped delimited and last row in text Total Row count
2. Create sample table: Create sample destination table in Test database 1: CREATE TABLE [dbo].[Employee](2: [EmployeeId] [int] IDENTITY(1,1) NOT NULL,3: [EmployeeNumber] [int] NULL,4: [EmployeeName] [varchar](50) NULL,5: CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED6: (7: [EmployeeId] ASC8: )9: )10: GO 3. Add Data Flow Task: Add data flow task in Package for transfer data source text file “Employee.txt” to sql server table “dbo.Employee” ![]() 4. Add new Flat File Connection: Right click on Connection Manager and add new Flat File connection ![]() 5. Set Flat file source properties: Flat file source properties set Connection manager Name, File Name (Source full filepath), column names in the first data row as a true ![]() 6. Add Flat file source: Add “Flat File Source” in “Data flow Task” and set properties Flat file connection manager and retain null values from the source as null values in the data flow as true and click button on preview and see in this file extra row include in text file ![]() 7. Add Conditional Split Transformation in Data Flow Task: Add Conditional Split Transformation in data flow task for split row ![]() 8. Set Condition Split Properties: Set properties Condition split where EmployeeNumber equal to “Total Row count” then this rows not use and other row use to process. ![]() 9. Add new OLE DB Connection: Right click on Connection Managers and add new OLE DB Connection ![]() 10. Set OLE DB Connection properties OLE DB Connection properties set Server Name, Connection to a database and click on ok button ![]() 11. Add OLE DB Destination: Add “OLE DB Destination” in “Data flow Task” and set properties OLE DB Connection Manager and Name of the table or the view ![]() 12. Set Input output selection : Set Input output selection between Condition spit and OLE DB Destination ![]() ![]() 13. Run package and Check : ![]() ![]() In this way we get split the information and use as per the requirement, Reference: Tejas Shah (www.SQLYoga.com) |
August 6, 2014
SQL SERVER: Clone SSIS Package
March 28, 2014
T-SQL to find out Space by File Group
SELECT fg.groupname AS 'File Group', Name, CONVERT (Decimal(15,2),ROUND(f.Size/128.000,2)) [Currently Allocated Space (MB)], CONVERT (Decimal(15,2), ROUND(FILEPROPERTY(f.Name,'SpaceUsed')/128.000,2)) AS [Space Used (MB)], CONVERT (Decimal(15,2), ROUND((f.Size-FILEPROPERTY(f.Name,'SpaceUsed'))/128.000,2)) AS [Available Space (MB)] FROM dbo.sysfiles f (NOLOCK) JOIN sysfilegroups fg (NOLOCK) ON f.groupid = fg.groupid ORDER BY fg.groupname
September 4, 2013
SQL SERVER: T-SQL to read all attributes of the XML
XML:
Expected Result:

Query to achieve the same:
DECLARE @XML AS XML SELECT @XML = '' SELECT CAST(x.v.query('local-name(.)') AS VARCHAR(100)) AS AttributeName ,x.v.value('.', 'VARCHAR(100)') AttributeValue FROM @XML.nodes('//@*') x(v) ORDER BY AttributeName
July 8, 2013
SQL Yoga: Parse XML with namespace with SQL SERVER
Recently, we were working on XML having namespace and we need to read that XML to fetch the information from the XML. Here, is the Sample XML which we are trying to parse: DECLARE @x XML If we need to fetch the “info” element with T-SQL we can write query as follows: ;WITH XMLNAMESPACES(DEFAULT 'http://schemas.microsoft.com/search/local/ws/rest/v1') Here, we have to use “WITH XMLNAMESPACES”, so we can specify the namespace of the XML that we are reading, else it wont give us any result. |
May 6, 2013
SQL Yoga – Read XML with T-SQL statement in SQL SERVER
In my previous post, “XML Result sets with SQL Server”, we review to generate result sets in XML from SQL server. Then I got a comment from the team, to also have post to read XML in SQL Server. To read XML in SQL server, is also simple. Lets read the XML which is created by XML PATH in previous post. Read XML Elements with T-SQL: DECLARE @SQLYoga TABLE( DECLARE @xml XML Now, please find query to read the query to read XML generated above: SELECT x.v.value('ID[1]', 'INT') AS ID, This query generates the output as follows: That’s it. It is much simple and you can get rid of the complex coding in application. Let me know your comments or issues you are facing while working on this. Reference: Tejas Shah (www.SQLYoga.com) |
May 3, 2013
SQLYoga – XML Result sets with SQL Server
Recently, found that people making much complex code to have an XML in application. I have found that they return result set in Table to the application and have applied code to convert that data table to XML by Asp. Net application. When I review the process, I have suggested that why don’t you use the XML feature of the application. They surprised the simple use of it and make their life easy. Let me have sample query to generate XML result sets in SQL Server database. There are two ways to have an XML from query: 1. FOR XML RAW 2. FOR XML PATH Please find following sample queries where both of the way are being used: Lets create sample data DECLARE @SQLYoga TABLE( Generate XML with XML ROW SELECT * XML RAW, returns the XML by each record with row element and all columns as attributes in the XML. Generate XML with XML PATH SELECT * XML PATH, returns the XML by each record with separate element and also columns as element within respected element of the record. That’s it. It is much simple and you can get rid of the complex coding in application. Let me know your comments or issues you are facing while working on this. Reference: Tejas Shah (www.SQLYoga.com) |
April 30, 2013
SQL SERVER: Backup the database and upload it on FTP and on Network
Recently one of my friend called me and asked me that his MS SQL SERVER Database server is crashed and the problem is, he has the database backups on the same server. So now as the server is crashed, and he cannot have any backup to restore the database. I suggested him, first get data recovery tool to get the data from crashed server and then restore it to make it work, so application will be up. Then, to overcome this kind of problem in future, I suggested him to always keep the database backup on another server and it is best to have database back up on another location too. He agreed with me that, and asked me a good question that: "Do you know if there is any kind of software by which I can schedule this and get out of this problem?" As he needs the solution quickly, I checked it out some Tools and I come with the very cool tool "SQL SERVER Backup And FTP". This is very simple to use. This tool works as:
We need to install this software on the server and we can take SQL SERVER Database backup on Network and FTP together. First please install this software from SQL SERVER Backup And FTP and Let me explain it how it works:
Here I have done following:
That's it and now we are out of stress to move database backup to another server or on FTP Let's click on "Run now" to check it out. After process is completed, Two zip files, pubs and SQLYoga is on Network path as well as on FTP. Another cool feature is that, we can schedule Full Backup, Differential Backup, and Transaction Backup, so we can have very minimal amount of data loss.
Here, I have configured this software as:
Here, we assume that it is ok that we have 15 minutes data loss. It is depends on your application to decide this time window. Let's take one case study to get more understanding about to restore these backups: e.g. Database server is crashed at 8:20 AM, How can I restore my database from the backups?
Another, option is also available, to remove old Differential backup and Transaction backup. Once new differential backup is generated, there is no need to keep old differential backup. We only need to restore recent differential backup, so we can remove old differential backups. We can also remove all transaction log backup which are generated before Differential Log. SO to remove old backups, this software is also providing an option for the same, we just need to checked this option and that's it. This software is also allowed following settings (advanced):
I like this tool, I recommend this tool to take back up and move it on FTP. Try to use it and let me know your comments |
November 5, 2012
SQL SERVER: Cross tab query with PIVOT
ctrl_no | id | Amount | OrderDate |
1000029 | 100016 | 990 | 10/25/2012 |
1000029 | 100018 | 990 | 10/25/2012 |
1000029 | 100016 | 660 | 10/26/2012 |
1000029 | 100018 | 660 | 10/26/2012 |
1000029 | 206007 | 660 | 10/26/2012 |
1000029 | 206007 | 660 | 10/27/2012 |
id | 10/25/2012 | 10/26/2012 | 10/27/2012 |
100016 | 990.00 | 660.00 | NULL |
100018 | 990.00 | 660.00 | NULL |
206007 | NULL | 660.00 | 660.00 |
CREATE TABLE #TestTable ( ctrl_no INT ,id INT ,Amount NUMERIC(18, 2) ,OrderDate DATE ) INSERT INTO #TestTable(ctrl_no , id , Amount , OrderDate ) SELECT 1000029,100016,990.0000,'10/25/2012' UNION ALL SELECT 1000029,100018,990.0000,'10/25/2012' UNION ALL SELECT 1000029,100016,660.0000,'10/26/2012' UNION ALL SELECT 1000029,100018,660.0000,'10/26/2012' UNION ALL SELECT 1000029,206007,660.0000,'10/26/2012' UNION ALL SELECT 1000029,206007,660.0000,'10/27/2012' SELECT id ,[10/25/2012] ,[10/26/2012] ,[10/27/2012] FROM ( SELECT id ,Amount ,OrderDate FROM #TestTable t ) x PIVOT(SUM(Amount) FOR OrderDate IN ( [10/25/2012] ,[10/26/2012] ,[10/27/2012] )) p DROP TABLE #TestTable
October 10, 2012
SQL SERVER: T-SQL to display Job history
We have multiple jobs running on the server as per the schedules. We need to have the status of the each job at the end of the day, so we can know that which jobs runs successfully and which gets failed. We have found the table, sysjobhistory, which contains history and get the list as per oyur requirements. Let me share the query:
Here, we have used “h.step_id = 0”, as we just concern about SQL server job status, we are not concerned about each step of the job. This query gives us result as follows: We have also configured, Notification email, which sends an email whenever job is getting failed. This query is used to review all job statuses together. Please let me know your comments Reference: Tejas Shah (http://www.SQLYoga.com) |
September 29, 2012
SQL SERVER: SSMS, Allow to create Stored procedure though table doesn’t exists
September 13, 2011
SQL SERVER: Load Reports without SQL SERVER Reporting Service with Asp.Net
Answer of his question is, YES. We can have reports without using SQL SERVER Reporting Service with same layout.
Microsoft Visual Studio is providing file called "RDLC" file, by which we can develop report in Microsoft Visual Studio and that Report doesn't need to deploy on Report server and will be called from Asp.Net application itself. By RDLC, it is very simple to load report in browser. We are out of issue to deploy reports on the Report Server and execute it from there. RDLC file remains there with project files.
In the Next post, I will explain in details to configure RDLC report with ASP.Net
June 15, 2011
Community TechDays at Ahmedabad, 2011
We had an excellent Community TechDays on 11th June 2011 at Ahmedabad. We have huge crowd to attend the sessions. Please find presentations and demos which speakers have presented during the session. | |||
![]() | Harish Vaidyanathan [twitter] Topic: HTML 5 | ||
![]() | Jacob Sebastian [twitter | blog] Topic: SQL SERVER Worst practices Download Presentation and Demo Files | ||
![]() | Pinalkumar Dave [twitter | blog] Topic: SQL SERVER Performance troubleshooting using Waits and Queues | ||
![]() | Topic: Asp.Net Tips and Tricks Download Presentation and Demo Files
| ||
We will upload this session photos soon
|
About Me

- Ahmedabad, Gujarat, India
- 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
Popular Posts
-
Today I have the following situation, where I need to display all related data in comma separated list. Till today we are using s...
-
With SSIS, most of the time we need to process all the files from the folder. Once file has been processed, we need to move the file to ...
-
Today, I have one requirement to check dynamically if a node exists in my xml or NOT. I have a stored procedure that receives XML and ...
-
Today, I am going to give basic example of Lookup Transformation Task in SSIS. Lookup transformation performs lookup operation by joini...