T-SQL

Monitoring BizTalk Server Without SCCM, using SQL query

For the environment that does not have SCCM to monitor BizTalk server health, the following SQL query can be incorporate into a SQL job and have BizTalk server at least on a "constant" check. Note: be aware that the following was tested only against a single suspended instance with a send port. Since BizTalk SQL server does not allow select against the ServiceClass table, I couldn't use a single table join. With the data I currently have, I am not 100% sure the Receive Port, Pipeline, Orchestration...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, September 14, 2011 10:37 PM | Feedback (0)

Do NOT trust CHECKSUM or BINARY_CHECKSUM in SQL, use HASHBYTES instead

We had a process ot using BizTalk to take in a reference file, then send data in via a table_type parameter in a stored procedure. The stored procedure uses a MERGE statement to insert and update; the update part of which does a CHECKSUM first to determine whether an update is even necessary. Then it happened, we had a reference row that should have been updated by the latest file, but it wasn't done. We checked the incoming and outgoing BizTalk Message in and out of the pipeline; everything looked...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Friday, May 20, 2011 8:50 PM | Feedback (1)

Frustration and rewards on using SSIS Pivot and Unpivot

Granted, if you are just transforming data in the same SQL server, why would you do it in SSIS instead of just using Pivot and Unpivot in T-SQL query? But what about in the case where data comes from various sources? What I had fun doing was the ability to skip using Linked server, pull in data from different sources, like XML over web service. Another point that made me happy was the ability to simulate ROW_NUMBER() function with the merged data by using a Script Component. Anyway, I highly recommend...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Friday, May 20, 2011 3:36 PM | Feedback (0)

Instead of alter table column to turn IDENTITY on and off, turn IDENTITY_INSERT on and off

First of all, I don't know which version of SQL this post (http://www.techonthenet.co... is based on, but at least for Microsoft SQL Server 2008, the syntax is not: ALTER TABLE [table_name] MODIFY [column_name] [data_type] NOT NULL; Instead, it should be: ALTER TABLE [table_name] ALTER COLUMN [column_name] [data_type] NOT NULL; Then, as several posts point out, you can't use T-SQL to run an existing column into an IDENTITY column. Instead, use the IDENTITY_INSERT to copy...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, March 02, 2011 11:24 PM | Feedback (0)

Change Data Capture to get a paricular set of change within a time span

The "fn_cdc_map_time_to_lsn" is especially useful DECLARE @begin_time datetime, @end_time datetime, @from_lsn binary(10), @to_lsn binary(10) SET @begin_time = '11/10/2010 10:00 AM' SET @end_time = '11/10/2010 8:00 PM' SET @from_lsn = sys.fn_cdc_map_time_to_lsn(... greater than or equal', @begin_time); SET @to_lsn = sys.fn_cdc_map_time_to_lsn(... less than or equal', @end_time); SELECT _OU.unit_natural_id AS Order_Id , CONVERT(DATETIME, LEFT(CONVERT(VARCHAR(80), _OR.return_body.query('...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, November 10, 2010 5:38 PM | Feedback (0)

Execute SQL Job synchronously for BizTalk via a Stored Procedure call

The async one was very easy to do. However, in the process automation task I was given, there was a need to execute SQL Job and waiting for the execution result. I couldn't find anything on the web to do what I wanted, so I make the following stored procedure. In addition, this stored procedure is quasi-synchronous. I start the job and then check the status. You can change the timing of the status check, but for the example below, it is "synchronous within 30 seconds." I wish there is a better way...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, November 01, 2010 3:18 PM | Feedback (0)

BizTalk UseAmbientTransaction and System.ObjectDisposedException

[UPDATE: 2010-10-15] This update is long overdue. Once we implemented all the changes, we were still getting that error from time to time. The sympton was that we would not get that error for hours, even days, but once we get it, the error keeps coming. After fiddling with some settings, we found that setting the "PollWhileDataFound" to False did the trick. We have not seen the error since. [UPDATE: 2010-08-26] We were able to fix our problem by setting the WCF-SQL receive location transaction isolation...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, August 25, 2010 10:46 AM | Feedback (2)

Comparing ways to get rowcount from a database table.

Just read this and found it very interesting. The following are 2 queries to get rowcount on a database table: Query 1 (the one everyone knows): SELECT COUNT(RowID) AS [RowCount] FROM elig_Inbox Query 2 (the interesting one): SELECT st.row_count AS [RowCount] FROM sys.dm_db_partition_stats st WHERE index_id < 2 and OBJECT_NAME(OBJECT_ID)='eli... What's really interesting to me is that once you look at the execution plan of the 2 queries, you'd find the improvement in performance. In real...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Thursday, February 25, 2010 10:07 AM | Feedback (1)

Stop a SQL job in the first 5 days of the month, but report success

It is actually quite simple when I think this through: Make the first job step with this T-SQL query: IF ((SELECT DAY(GETDATE())) < 6) BEGIN SELECT 1/0 END Go to the Advanced Tab of the Job Step property page. Select "Quit the job reporting sucess" on the "On Failure Action" drop down. Note: You can use RAISERROR, but the Severity has to be set to greater than 10. To avoid future maintenance confusion, I decided to go with the basic fatal error generation...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Tuesday, February 02, 2010 1:12 PM | Feedback (0)

Useful T-SQL queries on BizTalk Filter, Send Port, Receive Location, etc.

[2011-02-17] Disable all receive locations of Schedule adapter if the system has any suspended messages UPDATE RL SET RL.[Disabled] = -1 FROM BizTalkMgmtDb.dbo.adm_Recei... AS RL WITH(READPAST, ROWLOCK) INNER JOIN BizTalkMgmtDb.dbo.bts_recei... AS RP WITH(READPAST, ROWLOCK) ON RL.ReceivePortId = RP.nID INNER JOIN BizTalkMgmtDb.dbo.bts_appli... AS APP WITH(READPAST, ROWLOCK) ON RP.nApplicationID = APP.nID INNER JOIN BizTalkMgmtDb.dbo.adm_Adapter AS AD WITH(READPAST, ROWLOCK) ON RL.AdapterId...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, January 20, 2010 11:33 AM | Feedback (0)

BizTalk transaction even cover an "AFTER INSERT" trigger

This surprised me. I have a BizTalk SQL adapter calling a stored procedure to insert a row in some table. The table has an "AFTER INSERT" trigger on it. The original design had the trigger fire off an SSIS package. But when the SSIS is called, the row status is still not committed. I thought since I'm using an "AFTER INSERT" trigger, I was allowed to do that. Need to read more on the transaction nature of triggers, I guess
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, December 30, 2009 12:25 PM | Feedback (0)

Final note on creating PDF using SSRS and SSIS

Business Scenario: The client gets some kind of feeds that writes into a process table of their client processing system. The data is stored directly as the raw XML file inside a SQL data column. The XML could store multiple enrollment information for the same member. We need to use this info to determine whether a member is eligible, then insert into a staging table. The staging table is then used as a feed to drive a report that generates an image for each claim and sent off to the different provider....
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Tuesday, December 08, 2009 2:19 PM | Feedback (0)

Tricks to format XML properly for output from a SQL query

A few things I've learned in the past few days on SELECT {something} FOR XML AUTO, ELEMENTS Use subquery to denormalize data so that they can be grouped under the same parent element. Do not use synonym to get to your linked server. If you want any elements to be named properly, use full linked server syntax and alias the table/subquery. I'll add more as I learn them...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Thursday, December 03, 2009 1:44 PM | Feedback (0)

Calling SSRS report using either T-SQL or SSIS

[Update: 2009-12-30] We got it working using SSIS. Read this post: http://geekswithblogs.net/L... [Original post] Would love to know if there is a way to kick off a SSRS report and pass some parameters into it via T-SQL or SSIS. Unfortunately, we can't have MS SQL Enterprise edition. Guess this is the true list of possible solutions: VB script PowerShell WMI script batch file T-SQL Sad thing is I know how to make this...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Tuesday, November 24, 2009 2:53 PM | Feedback (0)

T-SQL extract multiple child node attribute data out of an XML datatype.

Business scenario: We have an XML file (HIPAA 837) saved as a XML data column in a table and we need to go through each row and get different information on different nodes and output to a table. The real reason of this design lies in with how the claim system is designed, which I will not try to explain here. Approach: Using Common Table Expression (CTE) to get all the necessary info so that the data can be joined later. Use ROW_NUMBER() to make sure the information comes from the correct line....
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, November 23, 2009 4:48 PM | Feedback (0)

Cannot do a reliable convert in the where clause for comparison

I'm dealing with this custom database where an attribute for an authorization can store many things (amount approved, flags, yes/no, etc.) For the attribute that store the amount approved, I have a job that starts off periodically to put a TermDate on it based on some business rules. I had an expression like this in the where clause: CONVERT(MONEY, @value, 1) > 10000 simply because @value comes in as a VARCHAR field. This fails, which I can understand. it's doing a table scan and failed when converting...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Tuesday, November 03, 2009 6:09 PM | Feedback (1)

Create synonym for all tables from another server or linked server object

I created the following into a stored procedure so that I can run it again and again: DECLARE @dynsqlcmd VARCHAR(250) DECLARE @tblname VARCHAR(150) DECLARE @synname VARCHAR(150) DECLARE @cnter INT -- Drop all synonyms DECLARE dbcursor CURSOR FOR SELECT sysobjects.name AS 'table name' FROM sysobjects WHERE sysobjects.type = 'sn' OPEN dbcursor FETCH NEXT FROM dbcursor INTO @synname WHILE (@@FETCH_STATUS =0) BEGIN SET @dynsqlcmd = 'DROP SYNONYM ' + @synname EXEC (@dynsqlcmd) FETCH NEXT FROM dbcursor...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Thursday, September 24, 2009 1:48 PM | Feedback (0)

Using xp_cmdshell to execute SSIS in a stored procedure

This is the code: DECLARE @SQLCommand AS VARCHAR(1000) SET @SQLCommand = '("dtexec location" /F "package location and name" ' + '/SET \package.Variables[User::your variable name].Value;' + CONVERT(VARCHAR(2), MONTH(@Date)) + '/' + CONVERT(VARCHAR(2), DAY(@Date)) + '/' + CONVERT(VARCHAR(4), YEAR(@Date)) + ')' EXEC xp_cmdshell @SQLCommand Some notes: I tried to pass in the date without formatting it, I get a "Option "1" is not valid" message. I had to convert the date into a string to include in the...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, September 23, 2009 12:41 PM | Feedback (0)

An awesome website on SQL code

Sometimes you have to resort to slang to express yourself, like on this ocasion there is nothing else to say except: "This dude is awesome". I used his stored procedure to script out that data in a table. Used to do this in TextPad with Regular expression. Can't imagine how much time this saves me. http://vyaskn.tripod.com/co
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, September 23, 2009 10:27 AM | Feedback (0)

Using sql update statement instead of cursor

I've seen too many instances where a cursor can be simply rewritten as an update statement. I was working at a client site where one of their process calls a stored procedure that uses a cursor do some updates. That stored procedure would run over the weekend to update about 2000 records and bog down the production SQL (You'd think I was joking). We re-write the stored procedure. Granted, the update itself is about 50 lines with 5 tables, subqueries, and left outer joins, but we got the stored procedure...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Friday, September 11, 2009 10:36 AM | Feedback (0)

Copyright © Kevin Shyr

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski