21 Aralık 2017 Perşembe

TSQL DECLARE CURSOR FOR

İlk TSQL Cursor Deneyimi,
     İhtiyaç dahilinde öğrenilmeyecek şey yoktur.
    Talep ve Arz meselesi, gerekeni gerektiği zaman yerine getiriyoruz.


 
DECLARE @ID uniqueidentifier
DECLARE @ADI VARCHAR(50)
declare @State smallint
declare @tbl Table (FullName nvarchar(100),State smallint,Name nvarchar(200),YukluMu nvarchar(5))
DECLARE CRS_PERSONEL CURSOR FOR
SELECT ID,FullName,State FROM Accounts.vw_UserDetails where Id is not NULL ORDER BY FullName

OPEN CRS_PERSONEL

FETCH NEXT FROM CRS_PERSONEL INTO @ID,@ADI,@State

WHILE @@FETCH_STATUS =0
 BEGIN 
insert into @tbl
select @ADI,@State,dt.Name,case when d.DocumentId is NULL then 'YOK' else 'VAR'end Yüklümü
 from Accounts.DocumentTypes dt
left join  Accounts.Documents d on d.PersonalId = @ID AND dt.Id = d.DocumentId 
where d.DocumentId is NULL or d.PersonalId = @ID and d.Active = 1 

  FETCH NEXT FROM CRS_PERSONEL INTO @ID,@ADI,@State
 
 END

CLOSE CRS_PERSONEL

DEALLOCATE CRS_PERSONEL
 select * from @tbl
where YukluMu ='YOK'
 

Öğrenmeden 1 gün dahi geçmemesi dileği ile ....

Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...

0 yorum

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
© 2013 Saygınlık Bilgelikte Gizlidir
Designed by Blog Thiet Ke
Posts RSSComments RSS
Yukarı