Selamlar









Kod:

--Translated by Maxis for Ko-Cuce.

create PROCEDURE [dbo].[itemyolla]

@StrUserID varchar(30),

@NEWNum int,

@StackSize int

AS

DECLARE

@length int,

@row int,

@i int,

@Num int,

@pos int,

@dur int,

@dur1 int,

@ext int,

@StackSize1 int,

@strName varchar(30),

@strExtName varchar(30),

@CNum varbinary(4),

@cdur varchar(2),

@cstack varchar(2)

BEGIN TRAN

If (@StackSize > 9999) or (@StackSize < 1)

begin

select @StrUserID, 0, 0, 0, 'Bilinmeyen StackSize kodu', ' 1 > 9999 olmali'

ROLLBACK TRAN

RETURN

end



Begin

set @i = 1

set @length =1601

Select @row = count(*) From userdata Where struserid like @StrUserID



If @row = 0 or @row > 1

Begin

Select @StrUserID, 0, 0, 0, 'Yanlis ID', 'Yeniden deneyin'

ROLLBACK TRAN

RETURN

End

Select @row = count(*) From userdata Where (struserid like @StrUserID) and (stritem is NULL)

If @row > 0

Begin

Select @StrUserID, 0, 0, 0, 'No Data', 'StrItem is NULL'

ROLLBACK TRAN

RETURN

End

End



WHILE @i < @length

Begin



Select @Num=cast(cast(substring(cast(substring(stritem, @i,4) as varbinary(4)), 4, 1)+substring(cast(substring(stritem, @i,4) as varbinary(4)), 3, 1)+substring(cast(substring(stritem, @i,4) as varbinary(4)), 2, 1)+substring(cast(substring(stritem, @i,4) as varbinary(4)), 1, 1) as varbinary(4)) as int),

@dur = cast(cast(cast( substring(stritem, @i+5, 1) as varbinary(1))+cast(substring(stritem, @i+4, 1) as varbinary(1)) as varbinary(2)) as smallint),

@StackSize1 = cast(cast(cast( substring(stritem, @i+7, 1) as varbinary(1))+cast(substring(stritem, @i+6, 1) as varbinary(1)) as varbinary(2)) as smallint)

From userdata

Where struserid = @StrUserID

If @Num = 0

begin

If @dur = 0

Begin

If @StackSize1 = 0

Begin

select @dur1 = Duration from ITEM where Num = @NEWNum



Set @dur = @dur + 1



If @StackSize > 1

Set @dur = 1

Set @CNum = Substring(cast(@NEWNum as varbinary(4)), 4, 1) + Substring(cast(@NEWNum as varbinary(4)), 3, 1) + Substring(cast(@NEWNum as varbinary(4)), 2, 1) + Substring(cast(@NEWNum as varbinary(4)), 1, 1)

Set @Cdur = cast(Substring(cast(@dur as varbinary(2)), 2, 1)+Substring(cast(@dur as varbinary(2)), 1, 1) as varchar(2))

Set @Cstack = cast(Substring(cast(@StackSize as varbinary(2)), 2, 1)+Substring(cast(@StackSize as varbinary(2)), 1, 1) as varchar(2))



Begin

--select cast(warehousedata as varbinary(1600)) from warehouse where strAccountID = @strUserID

--select cast( substring(WareHouseData, 1, @i-1) + cast(cast(@CNum as varchar(4)) + @Cdur + @Cstack as varchar(8)) + substring(WareHouseData, @i+8, 1601-@i) as binary(1600)) from warehouse where strAccountID = @strUserID

update userdata set stritem = cast( substring(stritem, 1, @i-1) + cast(cast(@CNum as varchar(4)) + @Cdur + @Cstack as varchar(8)) + substring(stritem, @i+8, 1601-@i) as binary(1600)) where struserid = @strUserID

COMMIT TRAN

RETURN

End

End

End

End

set @i = @i + 8

End



GO

itemyolla 'Char İd' , item kodu , adedi çalışıyor







Kullanımı ...








1 Başlat > Tüm Programlar > Microsoft SQL Server > Query Analyzer ‘ a giriyoruz.



2 SQL Server’ a bağlanıyoruz ve açılan ekranda ” master ” yerine ” DBmizi ” seçiyoruz.



3 Seçtikten sonra aşağıdaki kodu kopyalayıp , yapıştırıyoruz ve F5 yaparak kodumuzu uyguluyoruz.