Skip to main content

Posts

Call User-defined Function on Linked Server :SQL Server

If you try to invoke a user-defined function (UDF) through a linked server in SQL Server by using a "four-part naming" convention (server.database.dbo.Function), you may receive error message.  The reason is User-defined function calls inside a four-part linked server query are not supported in SQL Server. Thats why error message indicates that the syntax of a Transact-SQL statement is incorrect.  To work around this problem, use the Openquery function instead of the four-part naming convention. For example, instead of the following query Select * from Linked_Server.database.dbo.Function(10) run a query with the Openquery function: Select * from Openquery(Linked_Server,'select database.dbo.Function(10)') If the user-defined function takes variable or scalar parameters, you can use the sp_executesql stored procedure to avoid this behavior.  For example: exec Linked_Server.database.dbo.sp_executesql N'SELECT database.dbo.Function(@input)',N'@input...

Delete Duplicate Rows in SQL Server 2005

A new addition to the DELETE command in SQL Server 2005 is the TOP statement. The DELETE TOP does the same thing as a SELECT TOP WHERE only the TOP number of rows are deleted. This can be very helpful when there are duplicate rows of data present. DELETE TOP (1) FROM Sales.Customer WHERE CustomerID = 1 This would delete one of the duplicate rows for Customer number 1 Suppose somehow the whole customer table got duplicated. I duplicated the Sales.Customer table into a tmpCustomer table. SELECT Top 1 CustomerID, COUNT(CustomerID) AS Cnt FROM tmpCustomer GROUP BY CustomerID HAVING COUNT(CustomerID) > 1 WHILE @@RowCount > 0 BEGIN DELETE Top (1) FROM tmpCustomer WHERE CustomerID = (SELECT Top (1) CustomerID FROM tmpCustomer GROUP BY CustomerID HAVING COUNT(CustomerID) > 1) END While this worked just fine, it ran about 4 minutes for 38K rows. Let's try the dreaded CURSOR. ...

jQuery Image Swap with Effects

Swapping one image with another is probably one of the most used javascript techniques. Also Dreamweaver made “Image Replacement” even easier for non HTML/Javascript programmers by including this feature out of the box. One thing about Dreamweaver’s image swapping javascript is that it’s not the most beautiful javascript code. Well, as always with anything javascript related, jQuery is to the rescue. Query makes dynamic image swapping a peace of cake. Firstly you have to copy the following javascript code in the HEAD section of your page. You can also save the following javascript functions in a seperate js file. (function($) { $.fn.innerfade = function(options) { return this.each(function() { $.innerfade(this, options); }); }; $.innerfade = function(container, options) { var settings = { 'animationtype': 'fade', 'speed': 'fast', 'type...

SQL Bulk Copy with C#.Net

Bulk copying of data from one data source to another data source is a new feature added to ADO.NET 2.0. Bulk copy classes provides the fastest way to transfer set of data from once source to the other. Each ADO.NET data provider provides bulk copy classes. For example, in SQL .NET data provider, the bulk copy operation is handled by SqlBulkCopy class, which is described in Figure 1. As you can see from Figure 1, data from a data source can be copied to one of the four types - DataReader, DataSet, DataTable, or XML. Figure 1. Bulk Copy operation in ADO.NET 2.0 Using bulk copy operation, you can transfer data between two tables on the same SQL Server, between two different SQL Servers, or even two different types of database servers. using System.Data.SqlClient; public static void CopyData(DataTable sourceTable, SqlConnection destConnection, SqlTransaction destTrans, string destTableName) { // new method: SQLBulkCopy: using (SqlBulkCopy s = new SqlBulkC...

ASP.NET DropDownList with OptionGroup support

ASP.NET 2.0, for all its bells and whistles, lacks the odd bit of functionality for reasons completely unknown. One such notable omission is that of OptionGroup  ( < optgroup > ) support in the  DropDownList  control. For those unfamiliar with the  < optgroup >  element, it is part of the XHTML standard, and has the effect of categorising items in a  < select > , as the following image shows. Control Adapters are new in ASP.NET 2.0, and allow the developer to override the rendering behavior of any control, very powerful stuff! Furthermore, Control Adapters are used in conjunction with a browser file, so specific browsers may be targeted, if required. Armed with that knowledge, the solution became simple. The attached download contains the requisite files to implement this solution in your own projects, but for posterity, I paste it here also. public class DropDownListAdapter : System.Web.UI.WebControls.Adapters.WebCon...

Configure IP Address and Other Network Information in Windows 7

Configure IP Address and Other Network Information in Windows 7 Let me show you how to configure IP address and other network information in Windows 7 here. As you know IP address must be configured on computer in order to communicate with other computers, because this IP address is the standard address understood by computers and other networking devices in networking world. You can configure IP address, subnet mask, gateway and DNS servers manually on computer, but you can also configure computer to obtain IP address and other network information from DHCP server (most of the time is configured on router). Without wasting any more time, let me show you quick way to do it: 1) Go to  Start  and click on  Control Panel . 2) Proceed to click  View network status and tasks  in Control Panel window. 3) Network and Sharing Center window will appear, then click  change adapter settings . 4) Network Connections window will appears. Here you can right...

Running 32-bit Server Applications on 64-bit Machines

Running 32-bit Applications on 64-bit Windows (IIS 6.0) Windows Server 2003™, Service Pack 1 enables IIS 6.0 to run 32-bit Web applications on 64-bit Windows using the Windows-32-on-Windows-64 (WOW64) compatibility layer. IIS 6.0 using WOW64 is intended to run 32-bit personal productivity applications needed by software developers and administrators, including 32-bit Internet Information Services (IIS) Web applications. On 64-bit Windows, 32-bit processes cannot load 64-bit DLLs, and 64-bit processes cannot load 32-bit DLLs. If you plan to run 32-bit applications on 64-bit Windows, you must configure IIS to create 32-bit worker processes. Once you have configured IIS to create 32-bit worker processes, you can run the following types of IIS applications on 64-bit Windows: • Internet Server API (ISAPI) extensions • ISAPI filters • Active Server Page (ASP) applications (specifically, scripts calling COM objects where the COM object can be 32-bit or 64-bit) • ASP.NET applicat...