GRY-Online.pl --> Archiwum Forum

Zapytanie SQL i funkcja - potrzebna pomoc.

01.10.2009
17:09
smile
[1]

Grzesiek [ www eRepublik com PL ]

Zapytanie SQL i funkcja - potrzebna pomoc.

Korzystam z ASP.Net i domyślnego providera Profili.

W bazie kolumna PropertyNames trzyma takie wartości:
UkryjGG:S:0:4:LogCount:S:4:3: .... GG:...

Mam możliwość dobrania się z poziomu kodu do odpowiednich wartości, ale ostatnie robię to przez zapytanie SQL wykorzystując funkcję poniżej:




Wszystko fajnie, ale pojawił się problem.

Mianowicie mam pola: UkryjGG i GG.
Niestety, ale dla rekordów, które najpierw mają zapisane UkryjGG, a nie GG, zostaje zwracana wartość UkryjGG zamiast GG.

Czy ktoś mógłby mi pomóc z tą funkcją, tak by to działało i brało dokładnie wartość z GG, a nie UkryjGG?

Dziękuję :)


ALTER function [dbo].[FetchExtendendAttributeValue] (
@Key nvarchar(4000),
@Keys nvarchar(4000),
@Values nvarchar(4000)
)

RETURNS nvarchar(4000)
AS
BEGIN
DECLARE @Value nvarchar(4000)
Declare @CharIndex int
Declare @StartIndex int
Declare @Len int

--Find the index of the key
Set @CharIndex = CHARINDEX(@Key + ':s',@Keys)

--If the key does not exist, return NULL
if(@CharIndex = 0)
RETURN NULL

--If the key is not the first, remove any leading keys
if(@CharIndex > 1)
Begin
Set @Keys = Stuff(@Keys,1,@CharIndex-1,'')
End

--Remove the Key from the keys list. This will
Set @Keys = Stuff(@Keys,1,Len(@Key+':S:'),'')

--Find the location of the : after the starting location
Set @CharIndex = CHARINDEX(':',@Keys)

--Grab the starting location
Set @StartIndex = SUBSTRING(@Keys,1,@CharIndex-1)

--Remove the starting location from the Keys
Set @Keys = Stuff(@Keys,1,@CharIndex,'')

--Find the lenght value's index
Set @CharIndex = CHARINDEX(':',@Keys)

--Find the lenghth value
Set @Len = SUBSTRING(@Keys,1,@CharIndex-1)

--Get the value from the values string
Set @Value = SUBSTRING(@Values,@StartIndex+1,@Len)


RETURN @Value
END

01.10.2009
18:09
[2]

Grzesiek [ www eRepublik com PL ]

^

© 2000-2026 GRY-OnLine S.A.