It is estimated that a table is inserted in the stored procedure! So how can I find the process name?
Select object_name (ID) from syscomments where text like '% table name %'
Deletes the record with the last time record of the repeat ID.
ID name lastlogindate
001 A 2008-12-01
002 B 2008-12-03
001 A 2008-12-04
001
Delete 001
That is, if the ID is repeated, the last lastlogindate is left for deletion.
SQL code Delete TB from TB t where lastlogindate not in (select max (lastlogindate) from TB where id = T. ID)
Declare @ vendor_id int, @ vendor_name nvarchar (50), -- nested double-layer cursor Loop
@ Message varchar (80), @ Product nvarchar (50)
Print '-------- vendor products report --------'
Declare vendor_cursorCursorFor -- Define a cursor
Select vendorid, name from purchasing. Vendor where preferredvendorstatus = 1 order by vendorid
Open vendor_cursor -- open the cursor
Fetch next from vendor_cursorInto @ vendor_id, @ vendor_name extract the value of the current row to the variable
While @ fetch_status = 0 -- loop if a record row exists
Begin
Print''
Select @ message = '----- products from Vendor:' + @ vendor_name
Print @ message
-- The internal cyclic cursor must be defined internally.
Declare product_cursorCursorFor
Select v. name from purchasing. productvendor PV, production. Product v
Where pv. productid = V. productid and PV. vendorid = @ vendor_id -- the cursor takes the parameter to obtain the value from the outside.
Open product_cursor
fetch next from product_cursor into @ Product
If @ fetch_status <> 0
Print ' '
while @ fetch_status = 0
begin
select @ message = ''+ @ Product
Print @ message
fetch next from product_cursor into @ Product
end
close product_cursor
deallocate product_cursor
fetch next from vendor_cursor into @ vendor_id, @ vendor_name -- get the next supply data
end
close vendor_cursor