<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4198636189669615836</id><updated>2011-09-23T23:33:43.105-07:00</updated><category term='NOLOCK  READPAST'/><category term='Array Procedure'/><category term='SQL 2005 Gems'/><category term='query execution time'/><category term='connect by  prior'/><category term='comma seperated columns'/><category term='Password clear text'/><category term='SQL 2005  Level'/><category term='SQL 2005'/><category term='SQL webservice'/><category term='TSQL new features sql 2005'/><category term='sql 2005  output'/><category term='SQL server web interface'/><category term='Linked server'/><category term='Oracle'/><category term='SET statement SQL 2005'/><category term='SYS_REFCURSOR'/><category term='output display'/><category term='LPAD sql server'/><category term='primary  key  change sql server'/><category term='webservice'/><category term='Client Statistics sql server'/><category term='tree structrure'/><category term='current user'/><category term='Array Processing'/><category term='Stored procedure content'/><category term='SQL SERVER 2005'/><category term='dql procedure'/><category term='Remote procedure call'/><category term='Debug  sql2005 procedures'/><category term='coalesce'/><category term='Liinked server error'/><category term='Encryption sql  2005'/><category term='return table sql'/><title type='text'>Data -The Universal Base</title><subtitle type='html'>Thank you  for visiting my  blog site. I  am trying to scribble down a few facts and figures collated practically from almost one decade of professional experience in the world of binaries. I  hope the time you  spent on my site Helps you  to  gain what you  indented to. Happy  bloging :-) ..... &lt;br&gt; 
     "In the middle of difficulty lies opportunity" - Albert Einstein</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-1633128865508209520</id><published>2011-09-23T23:24:00.000-07:00</published><updated>2011-09-23T23:33:43.138-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Array Procedure'/><category scheme='http://www.blogger.com/atom/ns#' term='Array Processing'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><title type='text'>How to  pass array parameters  into  oracle stored procedure</title><content type='html'>There are various ways in which  you  could handle passing multiple records to  oracle stored procedures. The old style of handling this was passing the values as xml and process the xml  by  the procedure. This adds lots of overhead to the oracle processors. An alternate to  this is to  pass the array  in to  the procedure and iterate and insert the values to the table. this approach  may  be more meaningful  for the web applications with  UI  and middle tier separated out from database layer. This approach  will  significantly reduce the number of calls made to  the database layer from  middle tier. from  the .Net development environment, ODP.Net gives good options to  bind your parameter array to  stored procedures .  You could leverage that for better efficiency.&lt;br /&gt;&lt;br /&gt;Steps i  have scripted below are&lt;br /&gt;1. Creating a table to store the values&lt;br /&gt;2. Create a package with  the type and the procedure to  insert the values to  table using the array. &lt;br /&gt;3. PL SQL  script to try  executing the procedure from  the sqlplus.&lt;br /&gt;&lt;br /&gt;-- Drop  the existing test table&lt;br /&gt;Drop  table CPM_TESTTABLE;&lt;br /&gt;-- Create the new test table&lt;br /&gt;Create table CPM_TESTTABLE&lt;br /&gt;    (COL_NAME varchar2(20) , &lt;br /&gt;    COLN_NAME1 varchar2(10));&lt;br /&gt; &lt;br /&gt;--Create the package with  the type and the procedure&lt;br /&gt;CREATE OR REPLACE PACKAGE ARRAY_PKG AS &lt;br /&gt;    TYPE char_array1 IS TABLE OF VARCHAR2(20) INDEX BY BINARY_INTEGER;&lt;br /&gt;&lt;br /&gt;    PROCEDURE SPM_INS_TESTTABLE (&lt;br /&gt;        pColName IN char_array1,&lt;br /&gt;        pColName1 IN char_array1);&lt;br /&gt;END ARRAY_PKG;&lt;br /&gt;&lt;br /&gt;CREATE or REPLACE package body ARRAY_PKG as &lt;br /&gt;    PROCEDURE SPM_INS_TESTTABLE &lt;br /&gt;        (&lt;br /&gt;        pColName IN char_array1,&lt;br /&gt;        pColName1 IN char_array1&lt;br /&gt;        )&lt;br /&gt;    IS&lt;br /&gt;&lt;br /&gt;    BEGIN&lt;br /&gt;&lt;br /&gt;        FOR I IN 1..PCOLNAME.COUNT &lt;br /&gt;        LOOP   &lt;br /&gt;            INSERT INTO CPM_TESTTABLE&lt;br /&gt;            (COL_NAME,COLN_NAME1)&lt;br /&gt;            VALUES&lt;br /&gt;            (pColName(i),pColName1(i));&lt;br /&gt;&lt;br /&gt;        END LOOP;&lt;br /&gt;&lt;br /&gt;       EXCEPTION&lt;br /&gt;         WHEN OTHERS THEN&lt;br /&gt;           -- Consider logging the error and then re-raise&lt;br /&gt;           RAISE;&lt;br /&gt;    END SPM_INS_TESTTABLE;&lt;br /&gt; &lt;br /&gt;END ARRAY_PKG;&lt;br /&gt;&lt;br /&gt;-- PL sql  script to  execute the procedure with  array  inout parameter&lt;br /&gt;Declare&lt;br /&gt;     Customer_name ARRAY_PKG.char_array1; &lt;br /&gt;Begin&lt;br /&gt;     -- Adding 10 rows to the array&lt;br /&gt;     for i in 1..10 Loop&lt;br /&gt;        customer_name(i) := 'Ciju '|| to_char(i);&lt;br /&gt;     End Loop;&lt;br /&gt;      delete from CPM_TESTTABLE ; -- Useful while re re-running the test  &lt;br /&gt;      -- Call  the procedure using array  input&lt;br /&gt;        ARRAY_PKG.SPM_INS_TESTTABLE (customer_name , customer_name);&lt;br /&gt;End;&lt;br /&gt;commit;  &lt;br /&gt;SELECT *  FROM CPM_TESTTABLE&lt;br /&gt;-- End of script&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-1633128865508209520?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/1633128865508209520/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=1633128865508209520' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1633128865508209520'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1633128865508209520'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2011/09/how-to-pass-array-parameters-into.html' title='How to  pass array parameters  into  oracle stored procedure'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-8438782016749545462</id><published>2010-10-12T06:03:00.000-07:00</published><updated>2010-10-12T06:09:53.706-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='output display'/><category scheme='http://www.blogger.com/atom/ns#' term='SYS_REFCURSOR'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><title type='text'>Oracle - SYS_REFCURSOR Variable value listing</title><content type='html'>First step is to create a procedure with  out parameter datatype SYS_REFCURSOR&lt;br /&gt;-- Procedure creation&lt;br /&gt;CREATE OR REPLACE procedure cp_test1 (pgnum int ,pgrecords int ,pResultSet OUT  SYS_REFCURSOR)  is&lt;br /&gt;Begin&lt;br /&gt;Open  pResultSet for &lt;br /&gt;select * &lt;br /&gt;  from ( select a.*, rownum r &lt;br /&gt;           from ( select *&lt;br /&gt;                    from test1&lt;br /&gt;                   order by id ) a&lt;br /&gt;          where rownum &lt; (pgnum * pgrecords)+1) &lt;br /&gt; where r &gt; ((pgnum-1) * pgrecords);&lt;br /&gt;&lt;br /&gt;End;&lt;br /&gt;&lt;br /&gt;After the procedure is created,  please try below statements in SQL plus:&lt;br /&gt;sql &gt; set serveroutput on&lt;br /&gt;sql &gt; variable r1 refcursor&lt;br /&gt;sql &gt; exec cp_test1(1,20,:r1)&lt;br /&gt;sql &gt; print :r1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-8438782016749545462?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/8438782016749545462/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=8438782016749545462' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/8438782016749545462'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/8438782016749545462'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2010/10/oracle-sysrefcursor-variable-value.html' title='Oracle - SYS_REFCURSOR Variable value listing'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-1493850313176830957</id><published>2010-10-12T05:57:00.000-07:00</published><updated>2010-10-12T06:03:34.169-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='connect by  prior'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='tree structrure'/><title type='text'>Oracle - Search nodes of tree structure using connect by</title><content type='html'>&lt;strong&gt;Finding --Bottom to top relation&lt;/strong&gt;&lt;br /&gt;select entityunitid, entityname&lt;br /&gt;from table name&lt;br /&gt;connect by prior parentunitid = entityunitid&lt;br /&gt;start with entityunitid = bottom id&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;--Top to Bottom relation&lt;/strong&gt;&lt;br /&gt;select entityunitid, entityname&lt;br /&gt;from table name&lt;br /&gt;connect by prior entityunitid = parentunitid&lt;br /&gt;start with entityunitid = top id&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-1493850313176830957?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/1493850313176830957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=1493850313176830957' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1493850313176830957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1493850313176830957'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2010/10/oracle-search-nodes-of-tree-structure.html' title='Oracle - Search nodes of tree structure using connect by'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-2013919173115874709</id><published>2009-11-16T23:09:00.000-08:00</published><updated>2009-11-16T23:42:09.475-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='primary  key  change sql server'/><title type='text'>Change an existing primary key for table having  records; with a new identity column</title><content type='html'>&lt;b&gt;Steps to change an existing primary key for table having   records with a new identity  column :&lt;/b&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;-- Create a sample table with  primary  key&lt;/div&gt;&lt;div&gt;&lt;div&gt;Create table test3 ( id int  primary  key,  name char(2)) &lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;-- Insert some records to  this table&lt;/div&gt;&lt;div&gt;Insert into  test3 values (1,'cc')&lt;/div&gt;&lt;div&gt;Insert into  test3 values (2,'cq')&lt;/div&gt;&lt;div&gt;Insert into  test3 values (3,'cw')&lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;-- Add a new column (  this will  be set primary  key  in subsequent  steps)&lt;/div&gt;&lt;div&gt;Alter table test3 add new_id bigint&lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;-- Get and drop the primary key constraint (to  drop already created primary  key) &lt;/div&gt;&lt;div&gt;declare @cons_name varchar(300);&lt;/div&gt;&lt;div&gt;Select @cons_name  = name   from sysobjects where xtype = 'PK' and parent_obj in ( select id from sysobjects where xtype = 'U'  and name = 'test3')&lt;/div&gt;&lt;div&gt;exec (' Alter table test3 Drop constraint ' +  @cons_name) ;  &lt;/div&gt;&lt;div&gt;-- Update the new column with  the sequence  number&lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;Update test3  set test3.new_id = tt.a&lt;/div&gt;&lt;div&gt;From  (&lt;/div&gt;&lt;div&gt;Select row_number()  over (order by name)  as a ,name   from test3) tt&lt;/div&gt;&lt;div&gt;Where test3.name = tt.name&lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;-- Set the column as not null&lt;/div&gt;&lt;div&gt;alter table test3 alter column new_id bigint not null &lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;-- Set the new column as primary  key &lt;/div&gt;&lt;div&gt;alter table test3 add primary key (new_id)&lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;&lt;div&gt;Select *  from test3&lt;/div&gt;&lt;div&gt;&lt;div&gt;-- You could set the identity key to next value using dbcc_checkindent&lt;/div&gt;&lt;div&gt;-- DBCC CHECKIDENT ("table name", RESEED, 300)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;table&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-2013919173115874709?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/2013919173115874709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=2013919173115874709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/2013919173115874709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/2013919173115874709'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/11/change-existing-primary-key-for-table.html' title='Change an existing primary key for table having  records; with a new identity column'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-3485508145842931337</id><published>2009-10-04T23:03:00.000-07:00</published><updated>2009-10-04T23:30:32.381-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TSQL new features sql 2005'/><title type='text'>TSQL enhancements in SQL server 2005 # Part 1</title><content type='html'>&lt;div&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;1. &lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; border-collapse: collapse; "&gt;&lt;span class="PF"&gt;&lt;b&gt;TOP&lt;/b&gt;&lt;/span&gt; clause &lt;b&gt;with  TIES&lt;/b&gt; option  :  Select TOP(4) with  TIES * from test order by  idkey desc&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"&gt;2. Supports an&lt;b&gt; &lt;/b&gt;&lt;span class="PF"&gt;&lt;b&gt;OUTPUT&lt;/b&gt;&lt;/span&gt; clause so a single trip to the server performs the data update&lt;i&gt;and&lt;/i&gt; returns the results.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"&gt;3. &lt;span class="PF"&gt;&lt;b&gt;PIVOT&lt;/b&gt;&lt;/span&gt; operator provides the ability to quickly and easily generate cross tab queries. A cross tab query rotates rows data into columns data. : select VENDORID , [7],[8],[9] from MonthlyPurchaseOrders pivot (sum(subtotal) for Ordermonth in ( [7],[8],[9],[10]))  as a&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"&gt;4. Exception Handling with &lt;b&gt;TRY/CATCH&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"&gt;5. &lt;span class="PF"&gt;&lt;b&gt;ROW_NUMBER()&lt;/b&gt;&lt;/span&gt;&lt;b&gt; &lt;/b&gt;function creates a column that displays a number corresponding the row's position in the query result : select name, row_number() over (order by name)  from test&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"&gt;6. &lt;span class="PF"&gt;&lt;b&gt;RANK()&lt;/b&gt;&lt;/span&gt;&lt;b&gt; &lt;/b&gt;function works much like the &lt;span class="PF"&gt;ROW_NUMBER()&lt;/span&gt; function in that it numbers records in order. They differ in the way they work when duplicate values are contained in the &lt;span class="PF"&gt;ORDER BY&lt;/span&gt; expression.  : select name, row_number() over (order by name) , rank() over ( order by  name)  from test&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"&gt;7. &lt;span class="PF"&gt;&lt;b&gt;DENSE_RANK()&lt;/b&gt;&lt;/span&gt;&lt;b&gt; &lt;/b&gt;works the same way as &lt;span class="PF"&gt;RANK()&lt;/span&gt; does but eliminates the gaps in the numbering.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"&gt;8. &lt;span class="PF"&gt;&lt;b&gt;NTILE()&lt;/b&gt;&lt;/span&gt;&lt;b&gt; &lt;/b&gt;breaks the result set into a specified number of groups and assigns the same number to each record in a group&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px;"&gt;9. &lt;span class="Apple-style-span" style="font-weight: bold; "&gt;Common Table Expressions (CTE) &lt;span class="Apple-style-span" style="font-weight: normal; "&gt;A Common Table Expression (CTE) is a temporary result set created from a simple query&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-3485508145842931337?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/3485508145842931337/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=3485508145842931337' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/3485508145842931337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/3485508145842931337'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/10/tsql-enhancements-in-sql-server-2005.html' title='TSQL enhancements in SQL server 2005 # Part 1'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-3292946945721806958</id><published>2009-09-21T04:01:00.000-07:00</published><updated>2009-09-21T04:03:52.720-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='NOLOCK  READPAST'/><title type='text'>Using NOLOCK and READPAST table hints in SQL Server</title><content type='html'>&lt;h2&gt;NOLOCK&lt;/h2&gt; &lt;p&gt;This table hint, also known as READUNCOMMITTED, is applicable to SELECT  statements only. NOLOCK indicates that no shared locks are issued against the  table that would prohibit other transactions from modifying the data in the  table.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The following example shows how NOLOCK works and how dirty reads can occur.  In the script below, I begin a transaction and insert a record in the  SalesHistory table.&lt;/p&gt;&lt;pre&gt;&lt;pre&gt;SELECT COUNT(*) FROM SalesHistory WITH(NOLOCK)&lt;/pre&gt; &lt;p&gt;The number of records returned is 301. Since the transaction that entered the  record into the SalesHistory table has not been committed, I can undo it. I'll  roll back the transaction by issuing the following statement:&lt;/p&gt;&lt;pre&gt;ROLLBACK TRANSACTION&lt;/pre&gt; &lt;p&gt;This statement removes the record from the SalesHistory table that I  previously inserted. Now I run the same SELECT statement that I ran earlier:&lt;/p&gt;&lt;pre&gt;SELECT COUNT(*) FROM SalesHistory WITH(NOLOCK)&lt;/pre&gt; &lt;p&gt;This time the record count returned is 300. My first query read a record that  was not yet committed -- this is a dirty read.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;READPAST&lt;/h2&gt; &lt;p&gt;This is a much less commonly used table hint than NOLOCK. This hint specifies  that the database engine not consider any locked rows or data pages when  returning results&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The READPAST table hint example is very similar to the NOLOCK table hint  example. I'll begin a transaction and update one record in the SalesHistory  table.&lt;/p&gt;&lt;pre&gt;BEGIN TRANSACTION&lt;br /&gt;      UPDATE TOP(1) SalesHistory&lt;br /&gt;      SET SalePrice = SalePrice + 1&lt;/pre&gt; &lt;p&gt;Because I do not commit or roll back the transaction, the locks that were  placed on the record that I updated are still in effect. In a new query editor  window, run the following script, which uses READPAST on the SalesHistory table  to count the number of records in the table.&lt;/p&gt;&lt;pre&gt;SELECT COUNT(*)&lt;br /&gt;FROM SalesHistory WITH(READPAST)&lt;/pre&gt; &lt;p&gt;My SalesHistory table originally had 300 records in it. The UPDATE statement  is currently locking one record in the table. The script above that uses  READPAST returns 299 records, which means that because the record I am updating  is locked, it is ignored by the READPAST hint.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-3292946945721806958?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/3292946945721806958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=3292946945721806958' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/3292946945721806958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/3292946945721806958'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/09/using-nolock-and-readpast-table-hints.html' title='Using NOLOCK and READPAST table hints in SQL Server'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-5370224035979520206</id><published>2009-09-16T22:44:00.000-07:00</published><updated>2009-09-16T22:47:34.925-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Password clear text'/><category scheme='http://www.blogger.com/atom/ns#' term='Encryption sql  2005'/><title type='text'>SQL  2005 -  Save a password not as clear text</title><content type='html'>&lt;span class="Apple-style-span" style="font-size: medium;"&gt;In SQL Server 2005, you can use &lt;/span&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/ms174415.aspx" href="http://msdn2.microsoft.com/en-us/library/ms174415.aspx" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; color: rgb(0, 51, 204); cursor: pointer; text-decoration: none; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; list-style-type: none; "&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;HashBytes&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; to hash the password and &lt;/span&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/ms174361.aspx" href="http://msdn2.microsoft.com/en-us/library/ms174361.aspx" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; color: rgb(0, 51, 204); cursor: pointer; text-decoration: none; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; list-style-type: none; "&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;EncryptByKey&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; to encrypt it.&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 11px; "&gt;&lt;div class="CollapseRegionLink" style="cursor: pointer; color: rgb(0, 0, 0); font-weight: bold; font-size: 13px; text-decoration: none; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="CollapseRegionLink" style="cursor: pointer; color: rgb(0, 0, 0); font-weight: bold; text-decoration: none; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Examples&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MTPS_CollapsibleSection" style="padding-left: 10px; clear: both; display: block; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;a id="sectionToggle0" style="text-decoration: none; color: rgb(0, 51, 204); "&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;h3 class="subHeading" style="font-weight: 700; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;A. Simple symmetric encryption&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div class="subSection"&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;The following code shows how to encrypt a column by using a symmetric key.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;USE AdventureWorks;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;--If there is no master key, create one now. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;IF NOT EXISTS &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    (SELECT * FROM sys.symmetric_keys WHERE symmetric_key_id = 101)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    CREATE MASTER KEY ENCRYPTION BY &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    PASSWORD = '23987hxJKL969#ghf0%94467GRkjg5k3fd117r$$#1946kcj$n44nhdlj'&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;CREATE CERTIFICATE HumanResources037&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;   WITH SUBJECT = 'Employee Social Security Numbers';&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;CREATE SYMMETRIC KEY SSN_Key_01&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    WITH ALGORITHM = AES_256&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    ENCRYPTION BY CERTIFICATE HumanResources037;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;USE [AdventureWorks];&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- Create a column in which to store the encrypted data.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;ALTER TABLE HumanResources.Employee&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    ADD EncryptedNationalIDNumber varbinary(128); &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- Open the symmetric key with which to encrypt the data.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;OPEN SYMMETRIC KEY SSN_Key_01&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;   DECRYPTION BY CERTIFICATE HumanResources037;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- Encrypt the value in column NationalIDNumber with symmetric &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- key SSN_Key_01. Save the result in column EncryptedNationalIDNumber.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;UPDATE HumanResources.Employee&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;SET EncryptedNationalIDNumber = EncryptByKey(Key_GUID('SSN_Key_01'), NationalIDNumber);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- Verify the encryption.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- First, open the symmetric key with which to decrypt the data.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;OPEN SYMMETRIC KEY SSN_Key_01&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;   DECRYPTION BY CERTIFICATE HumanResources037;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- Now list the original ID, the encrypted ID, and the &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- decrypted ciphertext. If the decryption worked, the original&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-- and the decrypted ID will match.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;SELECT NationalIDNumber, EncryptedNationalIDNumber &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    AS 'Encrypted ID Number',&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    CONVERT(nvarchar, DecryptByKey(EncryptedNationalIDNumber)) &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    AS 'Decrypted ID Number'&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;    FROM HumanResources.Employee;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-5370224035979520206?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/5370224035979520206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=5370224035979520206' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/5370224035979520206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/5370224035979520206'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/09/sql-2005-save-password-not-as-clear.html' title='SQL  2005 -  Save a password not as clear text'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-6681016929561380176</id><published>2009-09-09T06:28:00.000-07:00</published><updated>2009-09-09T06:29:26.992-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql 2005  output'/><title type='text'>Output option in  SQL  2005</title><content type='html'>&lt;p&gt;"Output" provides you access to inserted and deleted logical tables. The data that has been inserted into the table OR the data after update statement has been executed, is available in inserted logical table.&lt;/p&gt;&lt;p&gt;declare @temptable table&lt;br /&gt;(&lt;br /&gt;empid int ,&lt;br /&gt;name varchar(60)&lt;br /&gt;)&lt;br /&gt;UPDATE AllEmployees set NAME = 'upd'&lt;br /&gt;OUTPUT inserted.employee_id , inserted.name into @temptable&lt;br /&gt;WHERE Employee_id = 9&lt;br /&gt;&lt;br /&gt;select * from @temptable&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-6681016929561380176?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/6681016929561380176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=6681016929561380176' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/6681016929561380176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/6681016929561380176'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/09/output-option-in-sql-2005.html' title='Output option in  SQL  2005'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-7815578555824838514</id><published>2009-09-09T06:08:00.000-07:00</published><updated>2009-09-09T06:11:45.650-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL 2005  Level'/><title type='text'>SQL 2005 use level  for hierarchy select</title><content type='html'>To get all the people in the hierarchy starting from Top management we could use the the following query:&lt;br /&gt;&lt;br /&gt;Create table AllEmployees ( Employee_id int primary key identity , name varchar(100), ManagerId int)&lt;br /&gt;select * from AllEmployees&lt;br /&gt;insert into AllEmployees(name,managerid) values ( E1, null)&lt;br /&gt;insert into AllEmployees(name,managerid) values ( E2, null)&lt;br /&gt;insert into AllEmployees(name,managerid) values ( 'E3' , 1)&lt;br /&gt;insert into AllEmployees(name,managerid) values ( 'E4' , 2)&lt;br /&gt;insert into AllEmployees(name,managerid) values ( 'E5' , 1)&lt;br /&gt;insert into AllEmployees(name,managerid) values ( 'E6' , 2)&lt;br /&gt;insert into AllEmployees(name,managerid) values ( 'E7' , 4)&lt;br /&gt;insert into AllEmployees(name,managerid) values ( 'E8' , 4)&lt;br /&gt;With LvlAllemployees as&lt;br /&gt;(&lt;br /&gt;select Allemployees.employee_id, Allemployees.name , Allemployees.managerid, 0 as level from AllEmployees where ManagerId is null&lt;br /&gt;union ALL&lt;br /&gt;select Allemployees.employee_id, Allemployees.name , Allemployees.managerid, level+1 as level from LvlAllEmployees&lt;br /&gt;inner join Allemployees on LvlAllemployees.employee_id = allemployees.managerid&lt;br /&gt;)&lt;br /&gt;select * from Lvlallemployees order by level&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-7815578555824838514?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/7815578555824838514/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=7815578555824838514' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/7815578555824838514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/7815578555824838514'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/09/sql-2005-use-level-for-hierarchy-select.html' title='SQL 2005 use level  for hierarchy select'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-995928334247656617</id><published>2009-07-20T22:13:00.000-07:00</published><updated>2009-07-20T22:16:03.473-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Stored procedure content'/><title type='text'>View contents of a Stored Procedure (quickly)</title><content type='html'>USe the procedure&lt;b&gt; &lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial; color: rgb(51, 51, 51); font-size: 12px; line-height: 18px; "&gt;&lt;b&gt;‘SP_HELPTEXT &lt;procname&gt;’&lt;/b&gt; &lt;/span&gt;to view the content of the stored rpocedure from  T-SQL .  If you  are extensive user of the T-SQL stored procedure, you  may  assing ehte short key  from Tools -&gt; Options -&gt; Keyboard and type in SP_HELPTEXT for a key of your choice.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-995928334247656617?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/995928334247656617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=995928334247656617' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/995928334247656617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/995928334247656617'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/07/view-contents-of-stored-procedure.html' title='View contents of a Stored Procedure (quickly)'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-1378575947211540972</id><published>2009-07-15T23:49:00.000-07:00</published><updated>2009-07-15T23:52:02.873-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='return table sql'/><category scheme='http://www.blogger.com/atom/ns#' term='dql procedure'/><title type='text'>Extract Data from Stored Procedure output into a Table in SQL</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 11px; "&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;b&gt;How to "Extract Data from Stored Procedure output into a Table in SQL"&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;There could be many ways to do this. If you are using SQL Server 2008 it would be better to  have  your stored procedure return a table variable. &lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Verdana;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="font-size: 11px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 11px; "&gt;If you are running prior versions best could be to  use  "INSERT INTO #tmpTable EXEC spStoredProcedure" method&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Verdana;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="font-size: 11px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="font-family:Verdana;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="font-size: 11px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-1378575947211540972?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/1378575947211540972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=1378575947211540972' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1378575947211540972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1378575947211540972'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/07/extract-data-from-stored-procedure.html' title='Extract Data from Stored Procedure output into a Table in SQL'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-187437703029924698</id><published>2009-07-15T22:40:00.000-07:00</published><updated>2009-07-15T22:47:46.552-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linked server'/><category scheme='http://www.blogger.com/atom/ns#' term='Remote procedure call'/><title type='text'>Calling Stored Procedure on Linked Server</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="Apple-style-span"   style=" color: rgb(51, 51, 51);  line-height: 19px; font-family:verdana;font-size:12px;"&gt;&lt;h2 style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Georgia, Verdana, Arial, serif; font-size: 1.4em; letter-spacing: 1px; "&gt;SQL SERVER – Executing&lt;/h2&gt;&lt;h2 style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Georgia, Verdana, Arial, serif; font-size: 1.4em; letter-spacing: 1px; "&gt; Remote Stored Procedure – Calling Stored Procedure on Linked Server - SQL  2000&lt;/h2&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Prerequirement : Create and configure the linked server&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Syntax  to  call the procedure : &lt;/div&gt;&lt;div&gt;EXEC [RemoteServer] .DatabaseName.DatabaseOwner.StoredProcedureName&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Please make sure the RPC is checked in  the property tab of Linked server (Server opt&lt;/div&gt;&lt;div&gt;ion tab)&lt;/div&gt;&lt;img src="http://4.bp.blogspot.com/_KD_Xb215ZxI/Sl6-PnlJWlI/AAAAAAAAA7w/Fko6UEyomcs/s320/blog1.JPG" style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 134px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5358929782149569106" /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-187437703029924698?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/187437703029924698/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=187437703029924698' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/187437703029924698'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/187437703029924698'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/07/calling-stored-procedure-on-linked.html' title='Calling Stored Procedure on Linked Server'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_KD_Xb215ZxI/Sl6-PnlJWlI/AAAAAAAAA7w/Fko6UEyomcs/s72-c/blog1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-1566826618286820599</id><published>2009-07-09T23:40:00.000-07:00</published><updated>2009-07-10T00:12:04.778-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SET statement SQL 2005'/><title type='text'>Usefull SET statements in  SQL 2005</title><content type='html'>&lt;strong&gt;&lt;span style="color:#3366ff;"&gt;Different SET statments that could be useful during development :&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;SET CONCAT_NULL_YIELDS_NULL  &lt;/strong&gt;: Controls whether concatenation results are treated as null or empty string values.&lt;br /&gt;&lt;strong&gt;SET ARITHABORT : &lt;/strong&gt;Terminates a query when an overflow or divide-by-zero error occurs during query execution&lt;br /&gt;&lt;strong&gt;SET FMTONLY : &lt;/strong&gt;Returns only metadata to the client. Can be used to test the format of the response without actually running the query&lt;br /&gt;&lt;strong&gt;SET IDENTITY_INSERT :&lt;/strong&gt; Allows explicit values to be inserted into the identity column of a table&lt;br /&gt;&lt;strong&gt;SET LANGUAGE :&lt;/strong&gt; Specifies the language environment for the session. The session language determines the datetime formats and system messages.&lt;br /&gt;&lt;strong&gt;SET NOEXEC : &lt;/strong&gt;Compiles each query but does not execute it.  &lt;em&gt;This  could be used to  check the syntax with  out executing the actual SQL.&lt;/em&gt;&lt;br /&gt;&lt;strong&gt;SET SHOWPLAN_TEXT / SET SHOWPLAN_XML: &lt;/strong&gt;Causes Microsoft SQL Server not to execute Transact-SQL statements. Instead, SQL Server returns detailed information about how the statements are executed.&lt;br /&gt;&lt;strong&gt;SET STATISTICS TIME : &lt;/strong&gt;Displays the number of milliseconds required to parse, compile, and execute each statement.&lt;br /&gt;&lt;strong&gt;SET STATISTICS XML :&lt;/strong&gt; Causes Microsoft SQL Server to execute Transact-SQL statements and generate detailed information about how the statements were executed in the form of a well-defined XML document.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-1566826618286820599?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/1566826618286820599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=1566826618286820599' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1566826618286820599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1566826618286820599'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/07/usefull-set-statements-in-sql-2005.html' title='Usefull SET statements in  SQL 2005'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-8065573466449778529</id><published>2009-07-09T22:34:00.000-07:00</published><updated>2009-07-09T22:40:50.134-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL 2005 Gems'/><title type='text'>Top 10 Hidden Gems in SQL Server 2005</title><content type='html'>&lt;p&gt;&lt;strong&gt;Top 10 Hidden Gems in SQL Server 2005&lt;br /&gt;&lt;/strong&gt;&lt;em&gt;Published: January 9, 2007 By Cihan Biyikoglu&lt;br /&gt;&lt;/em&gt;SQL Server 2005 has hundreds of new and improved components. Some of these improvements get a lot of the spotlight. However there is another set that are the hidden gems that help us improve performance, availability or greatly simplify some challenging scenarios. This paper lists the top 10 such features in SQL Server 2005 that we have discovered through the implementation with some of our top customers and partners.&lt;br /&gt;The order in the list does not have much significance except the specific instances we used them and the impact we saw. I will use a practical analogy; I started with the utility-knife size features that can help make life very easy at the right moment and build up to chain-saw size features that can help you implement a full scenario. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;TableDiff.exe &lt;/strong&gt;&lt;br /&gt;Table Difference tool allows you to discover and reconcile differences between a source and destination table or a view. Tablediff Utility can report differences on schema and data. The most popular feature of tablediff is the fact that it can generate a script that you can run on the destination that will reconcile differences between the tables. TableDiff.exe takes 2 sets of input;&lt;br /&gt;Connectivity - Provide source and destination objects and connectivity information.&lt;br /&gt;Compare Options - Select one of the compare options&lt;br /&gt;Compare schemas: Regular or Strict&lt;br /&gt;Compare using Rowcounts, Hashes or Column comparisons&lt;br /&gt;Generate difference scripts with I/U/D statements to synchronize destination to the source.&lt;br /&gt;TableDiff was intended for replication but can easily apply to any scenario where you need to compare data and schema.&lt;br /&gt;You can find more information about command line utilities and the Tablediff Utility in Books Online for SQL Server 2005.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Triggers for Logon Events (New in Service Pack 2)&lt;br /&gt;&lt;/strong&gt;With SP2, triggers can now fire on Logon events as well as DML or DDL events.&lt;br /&gt;Logon triggers can help complement auditing and compliance. For example, logon events can be used for enforcing rules on connections (for example limiting connection through a specific username or limiting connections through a username to a specific time periods) or simply for tracking and recording general connection activity. Just like in any trigger, ROLLBACK cancels the operation that is in execution. In the case of logon event that means canceling the connection establishment. Logon events do not fire when the server is started in the minimal configuration mode or when a connection is established through dedicated admin connection (DAC).&lt;br /&gt;The following code snippet provides an example of a logon trigger that records the information about the client connection.CREATE TRIGGER connection_limit_trigger&lt;br /&gt;ON ALL SERVER FOR LOGON&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;INSERT INTO logon_info_tbl SELECT EVENTDATA()&lt;br /&gt;END;&lt;br /&gt;You can find more information about this feature in updated Books Online for SQL Server Services Pack 2 un the heading “Logon Triggers”.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Boosting performance with persisted-computed-columns (pcc).&lt;br /&gt;&lt;/strong&gt;Btree Indexes provide great compromise for tuning queries vs redundant storage of data and added cost of modifying data (insert/update/delete). A less known capability for tuning in SQL Server 2005 is persisted computed columns (PCC). Computed columns can help you shift the runtime computation cost to data modification phase. The computed column is stored with the rest of the row and is transparently utilized when the expression on the computed columns and the query matches. You can also build indexes on the PCC’s to speed up filtrations and range scans on the expression.&lt;br /&gt;The following sample can demonstrate the benefits of a persisted computed column applied to a complex expression. The same TSQL query run against the following table schema with and without the DayType column will demonstrate the effect of the transparent expression matching with persisted computed columns. The output from the sys.dm_exec_query_stats DMV also shows the difference in the IO and CPU characteristics of the query.&lt;br /&gt;QuerySELECT [Ticker] ,[Date] , [DayHigh] ,[DayLow] ,[DayOpen] ,[Volume] ,[DayClose] ,[DayAdjustedClose],&lt;br /&gt;CASE&lt;br /&gt;WHEN volume &gt; 200000000 and dayhigh-daylow /daylow &gt; .05 THEN 'heavy volatility'&lt;br /&gt;WHEN volume &gt; 100000000 and dayhigh-daylow /daylow &gt; .03 THEN 'volatile'&lt;br /&gt;WHEN volume &gt; 50000000 and dayhigh-daylow /daylow &gt; .01 THEN 'fair'&lt;br /&gt;ELSE 'light'&lt;br /&gt;END as [DayType]&lt;br /&gt;FROM dbo.MarketData&lt;br /&gt;WHERE&lt;br /&gt;CASE&lt;br /&gt;WHEN volume &gt; 200000000 and dayhigh-daylow /daylow &gt; .05 THEN 'heavy volatility'&lt;br /&gt;WHEN volume &gt; 100000000 and dayhigh-daylow /daylow &gt; .03 THEN 'volatile'&lt;br /&gt;WHEN volume &gt; 50000000 and dayhigh-daylow /daylow &gt; .01 THEN 'fair'&lt;br /&gt;ELSE 'light'&lt;br /&gt;END = 'heavy volatility'&lt;br /&gt;Table SchemaCREATE TABLE [dbo].[MarketData](&lt;br /&gt;[ID] [bigint] IDENTITY(1,1) NOT NULL,&lt;br /&gt;[Ticker] [nvarchar](5) NOT NULL,&lt;br /&gt;[Date] [datetime] NOT NULL,&lt;br /&gt;[DayHigh] [decimal](38, 6) NOT NULL,&lt;br /&gt;[DayLow] [decimal](38, 6) NOT NULL,&lt;br /&gt;[DayOpen] [decimal](38, 6) NOT NULL,&lt;br /&gt;[Volume] [bigint] NOT NULL,&lt;br /&gt;[DayClose] [decimal](38, 6) NOT NULL,&lt;br /&gt;[DayAdjustedClose] [decimal](38, 6) NOT NULL,&lt;br /&gt;-- PERSISTED COMPUTED COLUMN --&lt;br /&gt;[DayType] AS (&lt;br /&gt;CASE&lt;br /&gt;WHEN volume &gt; 200000000 and dayhigh-daylow /daylow &gt; .05 THEN 'heavy volatility'&lt;br /&gt;WHEN volume &gt; 100000000 and dayhigh-daylow /daylow &gt; .03 THEN 'volatile'&lt;br /&gt;WHEN volume &gt; 50000000 and dayhigh-daylow /daylow &gt; .01 THEN 'fair'&lt;br /&gt;ELSE 'light'&lt;br /&gt;END) PERSISTED NOT NULL&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;Output From The Sys.Dm_Exec_Query_Stats Dynamic Management View (DMV)&lt;br /&gt;&lt;a id="ctl00_MTContentSelector1_mainContentContainer_ctl04" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_ctl00ctl00_MTContentSelector1_mainContentContainer_ctl04',this);" href="http://technet.microsoft.com/en-us/library/Cc917696.top10gems1(en-us,TechNet.10).jpg"&gt;&lt;/a&gt;&lt;br /&gt;.&lt;br /&gt;In the above picture, the output from sys.dm_exec_query_stats dynamic management view shows the difference in CPU and IO statistics between the same query hitting MarketData_Computed and MarketData tables. Line 1 represents the query run against the table with the persisted computed column. Line 2 is the table without the persisted computed column. With the complex expression pre-calculated in the DayType column, total worker time and overall elapsed time is lower compared to the table without the DayType persisted computed column.&lt;br /&gt;•Another way to verify that the persisted computed column is utilized, is to use the execution plan and look at the scan or the seek operator for the table with the computed column and check the output list, which should contain the column. In the example below you can see the DayType, the name for the PCC, in the output list under #9.&lt;/li&gt;&lt;li&gt; &lt;strong&gt;DEFAULT_SCHEMA setting in sys.database_principles&lt;br /&gt;&lt;/strong&gt;SQL Server provides great flexibility with name resolution. However name resolution comes at a cost and can get noticeably expensive in adhoc workloads that do not fully qualify object references. SQL Server 2005 allows a new setting of DEFEAULT_SCHEMA for each database principle (also known as “user”) which can eliminate this overhead without changing your TSQL code. Here is an example;&lt;br /&gt;In SQL Server 2005, the following query when executed by user1 that has a DEFAULT_SCHEMA of ‘dbo’ will directly resolve to dbo.tab1, instead of the extra search for user1.tab1. SELECT * FROM tab1&lt;br /&gt;Whereas the same query will search for ‘user1.tab1’ in SQL Server 2000 and if that does not exist it will resolve to ‘dbo.tab1’.&lt;br /&gt;This setting can be especially useful for databases upgraded from SQL Server 2000 to SQL Server 2005. To preserve the original behavior, databases upgraded from SQL Server 2000 will get the username as the DEFAULT_SCHEMA for each database principle. That means, in a database upgraded from a previous version to SQL Server 2005, ‘user1’ will get a DEFAULT_SCHEMA values of ‘user1’. To take advantage of the performance benefits, administrators can set the DEFAULT_SCHEMA through ALTER USER command and change it to the schema that most of the of the objects reside. Be aware this may break queries that may be utilizing objects in other schemas than the one set in the DEFAULT_SCHEMA setting and has not qualified the object names.&lt;br /&gt;DEFULT_SCHEMA is documented in Book Online under the “CREATE USER (Transact-SQL)” heading.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Forced Parameterization&lt;br /&gt;&lt;/strong&gt;Parameterization allows SQL Server to take advantage of query plan reuse and avoid compilation and optimization overheads on subsequent executions of similar queries. However there are many applications out there that, for one reason or another, still suffer from ad-hoc query compilation overhead. For those cases with high number of query compilation and where lowering CPU utilization and response time is critical for your workload, force parameterization can help.&lt;br /&gt;Force parameterization forces most queries to be parameterized and cached for reuse in subsequent submissions. Forced parameterization will remove the literal values and replaces them with parameters. This minimizes the compilation overhead for queries that are the same except the literal values in the query text. Forced parameterization is typically enabled at the database level. However it is also possible to hint FORCED PARAMETERIZATION on individual queries.&lt;br /&gt;In a number of cases, we have witnessed improvements in performance up to 30% due to forced parameterization. However forced parameterization can cause inappropriate plan sharing in cases where a single execution plan does not make sense. For those cases, you can utilize features like plan guides or query hints.&lt;br /&gt;You can find more information on Forced Parameterization in Books Online.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Vardecimal Storage Format&lt;br /&gt;&lt;/strong&gt;In Service Pack 2, SQL Server 2005 adds a new storage format for numeric and decimal datatypes called vardecimal. Vardecimal is a variable-length representation for decimal types that can save unused bytes in every instance of the row. The biggest amount of savings come from cases where the decimal definition is large (like decimal(38,6)) but the values stored are small (like a value of 0.0) or there is a large number of repeated values or data is sparsely populated.&lt;br /&gt;SQL Server 2005 also includes a stored procedure that can estimate the savings before you enable the new storage format.master.dbo.sp_estimate_rowsize_reduction_for_vardecimal ‘tablename’&lt;br /&gt;To enable vardecimal storage format, you need to first allow vardecimal storage on the database;exec sys.sp_db_vardecimal_storage_format N'databasename', N'ON'&lt;br /&gt;Once the database option is enabled, you can then turn on vardecimal storage at a table level using the following procedure;exec sp_tableoption 'tablename', 'vardecimal storage format', 1&lt;br /&gt;Vardecimal storage format presents an overhead due to the complexity inherent in variable length data processing. However in IO bound workloads, savings on IO bandwidth due to efficient storage can far exceed this processing overhead.&lt;br /&gt;If you would like more information on this topic, updated SQL Server 2005 Books Online for Service Pack 2 contains extensive information on the new vardecimal format.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Indexing made easier with SQL Server 2005&lt;br /&gt;&lt;/strong&gt;The new Dynamic Management Views have improved monitoring and trouble shooting greatly. A few of the dynamic management views (DMVs) deserve special attention.&lt;br /&gt;Through sys.dm_index_usage_stats you can find out how much maintenance and traversal you have for each index. Indexes with high maintenance numbers and low traversal numbers can be considered as good candidates for dropping.&lt;br /&gt;Through sys.dm_db_missing_index_* collection of DMVs, you can get recommendations on what new indexes could benefit the queries running on your server. The recommendations come with a estimate on how much improvement you can expect from the new index.&lt;br /&gt;If you’d like to automate creation and dropping of indexes, SQL Server Query Optimization Team has blogged about how to automate index recommendations into actions: &lt;a id="ctl00_MTContentSelector1_mainContentContainer_ctl12" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_ctl00ctl00_MTContentSelector1_mainContentContainer_ctl12',this);" href="http://blogs.msdn.com/queryoptteam/archive/2006/06/01/613516.aspx"&gt;http://blogs.msdn.com/queryoptteam/archive/2006/06/01/613516.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Figuring out the most popular queries in seconds&lt;br /&gt;&lt;/strong&gt;Another great DMV that can help save you a lot of work is sys.dm_exec_query_stats. In previous version of SQL Server to find out the highest impact queries on CPU or IO in system, you had to walk through a long set of analyses steps including getting aggregated information out of the data you collected from profiler.&lt;br /&gt;With sys.dm_exec_query_stats, you can figure out many combinations of query analyses by a single query. Here are some of the examples;&lt;br /&gt;Find queries suffering most from blocking – (total_elapsed_time – total_worker_time)&lt;br /&gt;Find queries with most CPU cycles – (total_worker_time)&lt;br /&gt;Find queries with most IO cycles – (total_physical_reads + total_logical_reads + total_logical_writes)&lt;br /&gt;Find most frequently executed queries – (execution_count)&lt;br /&gt;You can find more information on how to use dynamic management views for performance troubleshooting in the “SQL Server 2005 Waits and Queues” whitepaper located at: &lt;a id="ctl00_MTContentSelector1_mainContentContainer_ctl14" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_ctl00ctl00_MTContentSelector1_mainContentContainer_ctl14',this);" href="http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/performance_tuning_waits_queues.mspx"&gt;http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/performance_tuning_waits_queues.mspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Scalable Shared Databases&lt;br /&gt;&lt;/strong&gt;Scalable Shared Databases provide an alternative scale out mechanism for Read-Only environments. Through Scalable Shared Databases one can mount the same physical drives on commodity machines and allow multiple instances of SQL Server 2005 to work off of the same set of data files. The setup does not require duplicate storage for every instance of SQL Server and allows additional processing power through multiple SQL Server instances that have their own local resources like cpu, memory, tempdb and potentially other local databases. However this type of setup does limit the IO bandwidth since all instances point to the physical set of files.&lt;br /&gt;Book Online for SQL server 2005 contains details on Scalable Shared Databases.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Soft-NUMA&lt;br /&gt;&lt;/strong&gt;Highly concurrent workloads hit a contention point around global state they maintain at some point. That point in many cases happen to be ‘8’. One way around this contention has been to eliminate the global state and create hierarchies. NUMA architectures allow us to eliminate the contention around global resources by moving main resources closer to each other and forming nodes. SQL Server 2005 recognizes the NUMA architecture and self manages allocation of resources to adhere and take advantage of the hardware NUMA setup at the time of startup. By aligning with the HW setup SQL Server partitions its internal management to improve throughput.&lt;br /&gt;Some workloads benefit greatly from the partitioning concept, especially mixed workloads that have to run varying characteristics of data access concurrently (example: OLTP and Reporting). Soft-NUMA allows partitioning configuration to be extended into the software level and defined either on top of a NUMA enabled environment to further divide the hardware partitions into smaller chunks or on a machine that does not utilize NUMA concepts to enable partitioning for the configuration. By configuring partitions through Soft-NUMA, the administrator can control the allocation of schedulers and memory managers for each node and can configure specific TCP/IP ports for the nodes. Then, clients can be configured to connect using the specific ports to access specific partitions.&lt;br /&gt;Soft-NUMA topic is extensively covered in Book Online. You can also read more about the details of Soft-NUMA at Slava Oks’s Weblog at &lt;a id="ctl00_MTContentSelector1_mainContentContainer_ctl21" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_ctl00ctl00_MTContentSelector1_mainContentContainer_ctl21',this);" href="http://blogs.msdn.com/slavao/"&gt;http://blogs.msdn.com/slavao/&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;More details from  &lt;/p&gt;&lt;p&gt;&lt;a href="http://technet.microsoft.com/en-us/library/cc917696.aspx"&gt;http://technet.microsoft.com/en-us/library/cc917696.aspx&lt;/a&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-8065573466449778529?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/8065573466449778529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=8065573466449778529' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/8065573466449778529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/8065573466449778529'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/07/top-10-hidden-gems-in-sql-server-2005.html' title='Top 10 Hidden Gems in SQL Server 2005'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-2085118490119588532</id><published>2009-07-02T05:13:00.000-07:00</published><updated>2009-07-02T05:23:43.036-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL server web interface'/><title type='text'>Web Based Database Administration for SQL Server</title><content type='html'>&lt;p&gt;Microsoft SQL Web Data Administrator - Microsoft SQL Web Data Administrator application is a free tool from to perform typical SQL Server administration and development tasks. You have the ability to perform the following tasks: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Database, table, stored procedure, relational object, etc. creation, modification and deletion &lt;/li&gt;&lt;li&gt;Manage security &lt;/li&gt;&lt;li&gt;Import data and export relational objects&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Download and install the Microsoft SQL Web Data Administrator from - &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=C039A798-C57A-419E-ACBC-2A332CB7F959&amp;amp;displaylang=en" target="_blank"&gt;http://www.microsoft.com/downloads/details.aspx?familyid=C039A798-C57A-419E-ACBC-2A332CB7F959&amp;amp;displaylang=en&lt;/a&gt; &lt;/li&gt;&lt;li&gt;Run setup.msi to start the installation process.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Launching the Interface -&lt;/strong&gt; Navigate to Start All Programs Microsoft SQL Web Data Administrator SQL Web Data Administrator.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Launching the Application &lt;/strong&gt;- Once the interface loads, select the applicable port or just press the 'Start' button.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Login - &lt;/strong&gt;Specify the SQL Server instance, the authentication mode then press the 'Login' button.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Follow the menu options to make the basic SQL administrations. &lt;/p&gt;&lt;p&gt;example screen shot :&lt;/p&gt;&lt;p&gt;&lt;a href="http://4.bp.blogspot.com/_KD_Xb215ZxI/Skyl5vlLvVI/AAAAAAAAA7o/LnKXTNIZ7Ew/s1600-h/dataadm.gif"&gt;&lt;img id="BLOGGER_PHOTO_ID_5353836468480228690" style="WIDTH: 400px; CURSOR: hand; HEIGHT: 327px" alt="" src="http://4.bp.blogspot.com/_KD_Xb215ZxI/Skyl5vlLvVI/AAAAAAAAA7o/LnKXTNIZ7Ew/s400/dataadm.gif" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-2085118490119588532?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/2085118490119588532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=2085118490119588532' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/2085118490119588532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/2085118490119588532'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/07/microsoft-sql-web-data-administrator.html' title='Web Based Database Administration for SQL Server'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_KD_Xb215ZxI/Skyl5vlLvVI/AAAAAAAAA7o/LnKXTNIZ7Ew/s72-c/dataadm.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-7876251196722592840</id><published>2009-07-02T04:23:00.000-07:00</published><updated>2009-07-02T04:58:01.325-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='query execution time'/><category scheme='http://www.blogger.com/atom/ns#' term='Client Statistics sql server'/><title type='text'>Display of Client Statistics - to  find the execution time for select statements.</title><content type='html'>This could be used as an option to find the execution time for select statements:&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;When you execute a script or query in the Transact-SQL editor, you can choose to collect client statistics for each execution of the script or query. You use the client statistics to gather information about execution times, the amount of data sent between client and server, and so on &lt;/div&gt;&lt;div&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div&gt;&lt;strong&gt;To turn on or off the gathering of client statistics&lt;/strong&gt;&lt;br /&gt;Open a Transact-SQL editor session.&lt;br /&gt;On the Data menu, point to T-SQL Editor, and click Include Client Statistics.&lt;br /&gt;The menu item is a toggle. The first click turns on the gathering of client statistics, and the second click turns it back off. You can also toggle client statistics by clicking Include Client Statistics on the T-SQL Editor toolbar or by right-clicking in the T-SQL editor and then clicking Include Client Statistics.&lt;br /&gt;Execute a query in the T-SQL editor. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;If you turned on client statistics, the Client Statistics tab appears in the Results pane. If you turned off client statistics, the Client Statistics tab does not appear. &lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_KD_Xb215ZxI/SkybqviEaLI/AAAAAAAAA7Y/lwISqcBrgrY/s1600-h/Client+statistics.JPG"&gt;&lt;/a&gt;&lt;a href="http://2.bp.blogspot.com/_KD_Xb215ZxI/SkydTi5FnCI/AAAAAAAAA7g/ZgACMlPZ7xg/s1600-h/Client+statistics.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5353827016146000930" style="WIDTH: 400px; CURSOR: hand; HEIGHT: 184px" alt="" src="http://2.bp.blogspot.com/_KD_Xb215ZxI/SkydTi5FnCI/AAAAAAAAA7g/ZgACMlPZ7xg/s400/Client+statistics.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;You  could find details on this from : &lt;a href="http://msdn.microsoft.com/en-us/library/aa833228.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa833228.aspx&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-7876251196722592840?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/7876251196722592840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=7876251196722592840' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/7876251196722592840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/7876251196722592840'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/07/display-of-client-statistics-to-find.html' title='Display of Client Statistics - to  find the execution time for select statements.'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_KD_Xb215ZxI/SkydTi5FnCI/AAAAAAAAA7g/ZgACMlPZ7xg/s72-c/Client+statistics.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-3131384777016359752</id><published>2009-06-26T02:29:00.000-07:00</published><updated>2009-06-26T02:54:19.440-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='Linked server'/><title type='text'></title><content type='html'>Creation of linked server from SQL Server Management Studio&lt;br /&gt;1. Open SQL server Management Studio&lt;br /&gt;2. Connect to the database where you would like to create the linked server.&lt;br /&gt;3. Expand the note Sever Objects&lt;br /&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;a href="http://1.bp.blogspot.com/_KD_Xb215ZxI/SkSYjdftmdI/AAAAAAAAA7A/oCe_iRpB33c/s1600-h/img1.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5351569992203475410" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 282px; CURSOR: hand; HEIGHT: 121px" alt="" src="http://1.bp.blogspot.com/_KD_Xb215ZxI/SkSYjdftmdI/AAAAAAAAA7A/oCe_iRpB33c/s320/img1.JPG" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt;4. Choose the option New linked server.&lt;br /&gt;5. Update the below details&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;a href="http://3.bp.blogspot.com/_KD_Xb215ZxI/SkSYxkDOKnI/AAAAAAAAA7I/LvyOPxu4DKg/s1600-h/img2.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5351570234481191538" style="WIDTH: 280px; CURSOR: hand; HEIGHT: 320px" alt="" src="http://3.bp.blogspot.com/_KD_Xb215ZxI/SkSYxkDOKnI/AAAAAAAAA7I/LvyOPxu4DKg/s320/img2.JPG" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;a. Update the linked server name (This will be the name of the Linked server)&lt;br /&gt;b. Set the provider name as specified in the screen shot &lt;/div&gt;&lt;div&gt;c. Enter the product name&lt;br /&gt;d. Specify the Data source as&lt;br /&gt;Driver={SQL Server};Database=databasename;Server=servername;UID=userid;PWD=password;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;strong&gt;&lt;em&gt;Notes : &lt;/em&gt;&lt;/strong&gt;if you are facing any issues with accessing the database using the credentials provided , click on the Security tab and choose the security content and set the credentials. &lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/_KD_Xb215ZxI/SkSY-mqVAxI/AAAAAAAAA7Q/Wa7tAr7dPEs/s1600-h/img3.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5351570458520388370" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 320px; CURSOR: hand; HEIGHT: 162px" alt="" src="http://2.bp.blogspot.com/_KD_Xb215ZxI/SkSY-mqVAxI/AAAAAAAAA7Q/Wa7tAr7dPEs/s320/img3.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-3131384777016359752?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/3131384777016359752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=3131384777016359752' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/3131384777016359752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/3131384777016359752'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/06/creation-of-linked-server-from-sql.html' title=''/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_KD_Xb215ZxI/SkSYjdftmdI/AAAAAAAAA7A/oCe_iRpB33c/s72-c/img1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-4055290195145501482</id><published>2009-06-26T02:06:00.000-07:00</published><updated>2009-06-26T02:13:48.937-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Liinked server error'/><title type='text'>sql 2005 Linked server error</title><content type='html'>Why am i getting the error in Linked server :&lt;br /&gt;Msg 7313, Level 16, State 1, Line 1&lt;br /&gt;An invalid schema or catalog was specified for the provider "SQLNCLI" for linked server "Xyz".&lt;br /&gt;&lt;br /&gt;Mostly thie error appear when the link table referance is not made correctly. The select statement should refer the linked server table as&lt;br /&gt;linkserver name.database.dbo.table.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-4055290195145501482?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/4055290195145501482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=4055290195145501482' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/4055290195145501482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/4055290195145501482'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/06/sql-2005-linked-server-error.html' title='sql 2005 Linked server error'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-1189135182620300597</id><published>2009-06-25T04:37:00.000-07:00</published><updated>2009-06-25T04:50:51.505-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Debug  sql2005 procedures'/><title type='text'>Debug procedures in  SQL  2005</title><content type='html'>&lt;span class="ArticleParagraphTitle"&gt;Steps to  Debug a stored procedure&lt;/span&gt; in  sql 2005&lt;br /&gt;&lt;br /&gt;1. Open the Microsoft Visual Studio 2005&lt;br /&gt;2. Select Server Explorer option from  Menu as follows:&lt;br /&gt;&lt;br /&gt;&lt;img class="ArticleImage" src="http://www.dotnetfunda.com/UserFiles/ArticlesFiles/633304468003258418_Deeraj_1.JPG" /&gt;&lt;br /&gt;&lt;br /&gt;3. From the Data Connections node,  'Add connection'.&lt;br /&gt;&lt;br /&gt;&lt;img class="ArticleImage" src="http://www.dotnetfunda.com/UserFiles/ArticlesFiles/633304468524684690_Deeraj_2.JPG" /&gt;&lt;br /&gt;&lt;br /&gt;4. Expand the data connection  navigate to the Stored Procedures node.&lt;br /&gt;&lt;br /&gt;5. Select the intended SP to be debugged.&lt;br /&gt;&lt;br /&gt;6. Right click and  to view the Stored procedure.&lt;br /&gt;&lt;br /&gt;7. Place a break point on the intended line of code where debugging needs to be started.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img class="ArticleImage" src="http://www.dotnetfunda.com/UserFiles/ArticlesFiles/633304470045993106_Deeraj_3_1.JPG" /&gt;&lt;br /&gt;&lt;br /&gt;10. Right click on the stored procedure  select 'Step-Into Stored Procedure' as shown below.&lt;br /&gt;&lt;br /&gt;&lt;img class="ArticleImage" src="http://www.dotnetfunda.com/UserFiles/ArticlesFiles/633304472506556338_Deeraj_4.JPG" /&gt;&lt;br /&gt;&lt;br /&gt;11. This action brings parameter screen.&lt;br /&gt;&lt;br /&gt;&lt;img class="ArticleImage" src="http://www.dotnetfunda.com/UserFiles/ArticlesFiles/633304472945166930_Deeraj_5.JPG" /&gt;&lt;br /&gt;&lt;br /&gt;12. Enter the needful values and click Ok.&lt;br /&gt;&lt;br /&gt;&lt;img class="ArticleImage" src="http://www.dotnetfunda.com/UserFiles/ArticlesFiles/633304473698320850_Deeraj_6.JPG" /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-1189135182620300597?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/1189135182620300597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=1189135182620300597' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1189135182620300597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/1189135182620300597'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/06/debug-procedures-in-sql-2005.html' title='Debug procedures in  SQL  2005'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-2618215167309296302</id><published>2009-06-23T01:52:00.000-07:00</published><updated>2009-06-23T02:03:57.216-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='coalesce'/><category scheme='http://www.blogger.com/atom/ns#' term='comma seperated columns'/><title type='text'>Return the name and deaprtment in single column using  coalesce and function</title><content type='html'>&lt;strong&gt;-- Create some temp  tables&lt;/strong&gt;&lt;br /&gt;IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DEPT]') AND type in (N'U'))&lt;br /&gt;DROP TABLE [dbo].[DEPT]&lt;br /&gt;GO&lt;br /&gt;CREATE TABLE DEPT (ID INT , DEPT VARCHAR(100))&lt;br /&gt;INSERT INTO DEPT VALUES (10,'ACCOUNTING')&lt;br /&gt;INSERT INTO DEPT VALUES (20,'MARKETING')&lt;br /&gt;INSERT INTO DEPT VALUES (30,'FINANCE')&lt;br /&gt;GO&lt;br /&gt;IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SNAME]') AND type in (N'U'))&lt;br /&gt;DROP TABLE [dbo].[SNAME]&lt;br /&gt;GO&lt;br /&gt;CREATE TABLE SNAME (ID INT , DEPT INT , SNAME VARCHAR(100))&lt;br /&gt;INSERT INTO SNAME VALUES (1,10,'HARISH')&lt;br /&gt;INSERT INTO SNAME VALUES (2,20,'HARISH')&lt;br /&gt;INSERT INTO SNAME VALUES (2,20,'CIJU')&lt;br /&gt;INSERT INTO SNAME VALUES (2,30,'CIJU')&lt;br /&gt;INSERT INTO SNAME VALUES (5,10,'CIJU')&lt;br /&gt;GO&lt;br /&gt;&lt;strong&gt;-- Drop  and create the Functions for Comma seperated value return. &lt;/strong&gt;&lt;br /&gt;IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[COMA_CP1]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))&lt;br /&gt;DROP FUNCTION [dbo].[COMA_CP1]&lt;br /&gt;GO&lt;br /&gt;CREATE FUNCTION COMA_CP1(@SNAME1 VARCHAR(100)) RETURNS VARCHAR(2000)&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;DECLARE @RES VARCHAR(100)&lt;br /&gt;SELECT @RES = COALESCE(@RES + ', ', '') + DEPT1.DEPT&lt;br /&gt;FROM SNAME&lt;br /&gt;INNER JOIN DEPT DEPT1&lt;br /&gt;ON SNAME.DEPT = DEPT1.ID&lt;br /&gt;WHERE SNAME = @SNAME1&lt;br /&gt;RETURN @SNAME1 +','+ @RES&lt;br /&gt;END&lt;br /&gt;GO&lt;br /&gt;&lt;strong&gt;-- Final  select to  Return &lt;br /&gt;&lt;/strong&gt;SELECT DBO.COMA_CP1(SNAME)&lt;br /&gt;FROM SNAME&lt;br /&gt;INNER JOIN DEPT DEPT1&lt;br /&gt;ON SNAME.DEPT = DEPT1.ID&lt;br /&gt;GROUP BY SNAME&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-2618215167309296302?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/2618215167309296302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=2618215167309296302' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/2618215167309296302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/2618215167309296302'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/06/return-name-and-deaprtment-in-single.html' title='Return the name and deaprtment in single column using  coalesce and function'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-9030593377537558412</id><published>2009-06-19T06:10:00.000-07:00</published><updated>2009-06-19T06:18:00.467-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL SERVER 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='LPAD sql server'/><title type='text'>LPAD function in sql  server</title><content type='html'>In PL/SQL  we have the statement LPAD(string, length, pad), RPAD(string, length, pad)Returns string padded on left or right to length characters using the pad string as padding. Here is an example that provied the similar functioanlity in  sql  server&lt;br /&gt;&lt;br /&gt;declare @in_val int&lt;br /&gt;set @in_val = 1&lt;br /&gt;select 'R'+right(replicate('0',3)+CAST(@in_val AS VARCHAR),2)&lt;br /&gt;If you pass  1 as input val  this will  return 'R01' ,  for value 10  this will return 'R10'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-9030593377537558412?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/9030593377537558412/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=9030593377537558412' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/9030593377537558412'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/9030593377537558412'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/06/lpad-function-in-sql-server.html' title='LPAD function in sql  server'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-3947310917231102118</id><published>2009-06-11T22:30:00.000-07:00</published><updated>2009-06-11T22:31:40.073-07:00</updated><title type='text'>Distinct xtype values in sysobjects</title><content type='html'>&lt;a href="http://brainof-dave.blogspot.com/2006/11/xtype-values-in-sysobjects.html"&gt;xtype values in sysobjects&lt;/a&gt;&lt;br /&gt;This is a list of all of the possible values for the xtype column in the sysobjects table of a SQL Server database:&lt;br /&gt;C - CHECK constraint&lt;br /&gt;D - Default or DEFAULT constraint&lt;br /&gt;F - FOREIGN KEY constraint&lt;br /&gt;L - Log&lt;br /&gt;P - Stored procedure&lt;br /&gt;PK - PRIMARY KEY constraint&lt;br /&gt;RF - Replication filter stored procedure&lt;br /&gt;S - System table&lt;br /&gt;TR - Trigger&lt;br /&gt;U - User table&lt;br /&gt;UQ - UNIQUE constraint&lt;br /&gt;V - View&lt;br /&gt;X - Extended stored procedure&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-3947310917231102118?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/3947310917231102118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=3947310917231102118' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/3947310917231102118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/3947310917231102118'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/06/distinct-xtype-values-in-sysobjects.html' title='Distinct xtype values in sysobjects'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-233306841720978023</id><published>2009-06-04T08:06:00.000-07:00</published><updated>2009-06-04T08:07:10.339-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='current user'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL 2005'/><title type='text'>To get the current user in  TSQL - SQL 2005</title><content type='html'>&lt;p style="text-align: justify;"&gt;To get current user run following script in Query Editor&lt;/p&gt; &lt;p&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: magenta;"&gt;SYSTEM_USER&lt;/span&gt;&lt;/code&gt;&lt;/p&gt; &lt;p style="text-align: justify;"&gt;SYSTEM_USER will return current user. From Book On-Line – SYSTEM_USER returns the name of the currently executing context. If the EXECUTE AS statement has been used to switch context, SYSTEM_USER returns the name of the impersonated context.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-233306841720978023?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/233306841720978023/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=233306841720978023' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/233306841720978023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/233306841720978023'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/06/to-get-current-user-in-tsql-sql-2005.html' title='To get the current user in  TSQL - SQL 2005'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4198636189669615836.post-6867686763075394997</id><published>2009-05-11T09:43:00.000-07:00</published><updated>2009-05-11T10:00:10.709-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='webservice'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL webservice'/><title type='text'>Native XML Web Services for Microsoft SQL Server 2005</title><content type='html'>&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;Intro :&lt;/strong&gt;&lt;br /&gt;Microsoft SQL Server 2005 provides a standard mechanism for accessing the database engine using SOAP via HTTP. Using this mechanism, you can send SOAP/HTTP requests to SQL Server to execute: &lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;Transact-SQL batch statements, with or without parameters. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;Stored procedures, extended stored procedures, and scalar-valued user-defined functions.&lt;/span&gt; &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;br /&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;SQL Server 2005-native Web services require Microsoft Windows Server 2003 as the operating system, because they rely on the kernel mode http driver http.sys that this version provides. Since SQL Server leverages the kernel mode http.sys driver, you do not necessarily need to have IIS installed to expose Web services out of SQL Server; this simplifies administration. Instead, you should base your decision to install IIS on application requirements. For example, certain applications benefit from having an explicit middle tier. In such cases, IIS would be useful.&lt;/span&gt;&lt;/div&gt;&lt;strong&gt;CREATE HTTP ENDPOINT&lt;/strong&gt;&lt;br /&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;HTTP Endpoints are created and administered using Transact-SQL DDL. Creating an HTTP Endpoint is the first step in enabling HTTP/SOAP access to SQL Server 2005. Each endpoint has a name and a collection of options that when combined define the behavior of the endpoint.&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;To illustrate how the CREATE HTTP ENDPOINT is used, let's take a look at a Hello World example for invoking a stored procedure via SQL Server Web Services.&lt;br /&gt;First, create a stored procedure called hello world in the master database, using the following T-SQL. This stored procedure simply displays the string provided in the input parameter.&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;CREATE PROCEDURE hello_world(@msg nvarchar(256))AS &lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;BEGIN&lt;br /&gt;select @msg as 'message'&lt;br /&gt;END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Next, use the following T-SQL to create the HTTP endpoint which will allow access to this stored procedure as a WebMethod:&lt;br /&gt;&lt;br /&gt;CREATE ENDPOINT hello_world_endpoint&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;STATE = STARTEDAS HTTP ( AUTHENTICATION = ( INTEGRATED ), &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;PATH = '/sql/demo', PORTS = ( CLEAR ))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;FOR SOAP ( WEBMETHOD 'http://tempuri.org/'.'hello_world' &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;(NAME = 'master.dbo.hello_world'), &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;BATCHES = ENABLED, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;WSDL = DEFAULT ) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;All endpoints are stored in master, in the metadata view master.sys.http_endpoints. An endpoint doesn't have any SOAP Methods unless you define them. In the above example, we exposed the stored procedure master.dbo.hello_world as WebMethod 'hello_world'; the WebMethod can have any name and, for example, could have been called as 'testproc1' under the 'http://tempuri.org' namespace. Specifying DEFAULT as the value for WSDL clause enables the endpoint to respond to requests for WSDL generating WSDL using the default format. You can suppress WSDL generation by setting WSDL=NONE in the above statement. We discuss the details of WSDL generation in a subsequent section&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;strong&gt;WSDLWSDL&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size:85%;"&gt;is a document written in XML that describes a Web service. It specifies the location of the service and the operations (or methods) the service exposes. WSDL provides the information necessary for a client to interact with a Web service. Tools such as Visual Studio .NET and Jbuilder use the WSDL to generate proxy code that client applications can use to communicate with a Web service. If the endpoint has WSDL enabled, that endpoint will produce WSDL when it receives a request for it. The endpoint created earlier in this article will produce WSDL when an authenticated request is sent to it. A WSDL request is a simple HTTP get request of the form.&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;a href="http://servername/sql/demo?wsdl"&gt;&lt;span style="font-size:85%;"&gt;http://servername/sql/demo?wsdl&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;For more details Turn to : &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms345123.aspx"&gt;&lt;span style="font-size:85%;"&gt;http://msdn.microsoft.com/en-us/library/ms345123.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-size:78%;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4198636189669615836-6867686763075394997?l=cijupeter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cijupeter.blogspot.com/feeds/6867686763075394997/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4198636189669615836&amp;postID=6867686763075394997' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/6867686763075394997'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4198636189669615836/posts/default/6867686763075394997'/><link rel='alternate' type='text/html' href='http://cijupeter.blogspot.com/2009/05/intro-microsoft-sql-server-2005.html' title='Native XML Web Services for Microsoft SQL Server 2005'/><author><name>Ciju's</name><uri>http://www.blogger.com/profile/15212934121448774256</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
