Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Convert VB Script function to T-SQL

Author  Topic 

duanecwilson
Constraint Violating Yak Guru

273 Posts

Posted - 2012-01-12 : 15:48:04
I have this function from VB Script and I thought it would be easy to convert, but I must have a mental block. Maybe someone could point me the right way:
Function ScrubMyID (Type,Aid,AltID,I_Number)
SELECT CASE Type
CASE "00"
ScrubMyID = AltID
CASE "01"
ScrubMyID = Aid
CASE "02"
ScrubMyID = AltID
CASE "03"
ScrubMyID = AltID
END SELECT
IF MID(ScrubMyID,1,1) = "." THEN ScrubMyID = I_Number
End Function


Duane

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-13 : 03:56:27
its almost the same

CREATE FUNCTION ScrubMyID
(
@Type varchar(5),
@Aid int,
@AltID int,
@I_Number int
)
RETURNS int
AS
BEGIN
DECLARE @RID int
SELECT @RID = CASE
WHEN @Type IN ('00','02','03') THEN AltID
WHEN @Type ='01' THEN Aid
END
SELECT @RID = CASE WHEN LEFT(@RID,1) = '.' THEN @I_Number ELSE @RID END
RETURN @RID
END


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

duanecwilson
Constraint Violating Yak Guru

273 Posts

Posted - 2012-01-13 : 15:05:26
Thank you. This is good, better than the work-around I finally figured out late yesterday.

Duane
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-14 : 00:02:21
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -