Thursday, January 12, 2012

SQL Notes

Find all references of a given stored proc or a given string.

syscomments has the body text for all user stored procs in the system.
So you may search all stored procs that contain a given text.
Suppose you want to see all references for a stored proc named up_MyProc.
You may accomplish this as follows:

declare @keyword nvarchar(100)
set @keyword = 'up_MyProc' -- Enter the key word here like 'OptInInd'
SELECT distinct 'sp_helptext ' + o.name
FROM syscomments s, sys.objects o
where s.id = o.object_id
and o.type = 'P'
and charindex(@keyword, s.text) > 0





******



The syntax for using an alias in an update statement on SQL Server is as follows:
UPDATE QSET Q.TITLE = 'TEST'
FROM HOLD_TABLE QWHERE Q.ID = 101;
So one could write and update based on selected rows:
 update pv 
  set pv.[LocalizedText]= (Select [LocalizedText] from [Np2n.v2.eCoCommon].[dbo].[LocalizationItem] as nv 
  where nv.[LocalizationItemID]='NP_Review_ShipMethod_Header' and 
nv.cultureid=pv.cultureid)  from  [Np2n.v2.eCoCommon].[dbo].[LocalizationItem] pv where   pv.[LocalizationItemID]='GG_Review_ShipMethod_Header' 
******
Mutliple  insert from another source:
INSERT INTO Store_Information (store_name, Sales, Date)
SELECT store_name, Sales, Date
FROM Sales_Information
WHERE Year(Date) = 1998

No comments: