Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Server Select Statement
Message
 
 
To
21/07/2005 10:56:20
Stephen Hunt
Admit Computer Services Inc.
Farmingdale, New York, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01034265
Message ID:
01034677
Views:
28
It doesn't help much because you may not need UDF after all. Anyway, there're a couple ways to implement such UDF()
-- #1
if @module='MV'
        SELECT @judgecode= mv_judge FROM motorvehicle
        WHERE keyident = @keyident
else if @module='LL'
        SELECT @judgecode= ll_judge FROM locallaw
        WHERE keyident = @keyident
else if @module='CV'
        SELECT @judgecode=civ_judge FROM civil
        WHERE keyident = @keyident
else if @module='CRM'
        SELECT @judgecode=crm_judge FROM criminal
        WHERE keyident = @keyident
else if @module='SC'
        SELECT @judgecode=sc_judge FROM smallclaims
        WHERE keyident = @keyident

RETURN (@judgecode)
---------------------------------------------------
-- #2
SELECT @judgecode= mv_judge FROM motorvehicle
	WHERE @module='MV' AND keyident = @keyident
UNION ALL	
SELECT @judgecode= ll_judge FROM locallaw
	WHERE @module='LL' AND keyident = @keyident
...

UNION ALL	
SELECT @judgecode=sc_judge FROM smallclaims
        WHERE @module='SC' AND keyident = @keyident
RETURN (@judgecode)
Please enclose your code in < pre> and < /pre> tags (w/o spaces) so it's easier to read.

>Ok here is my scalar UDF
>CREATE FUNCTION fn_getjudge(@module char(10), @keyident nvarchar (12))
>RETURNS char(3)
>begin
>DECLARE @judgecode Char(3)
>  SET @judgecode=''
>if @module='MV'
>        SELECT @judgecode= mv_judge FROM motorvehicle
>        WHERE keyident = @keyident
>RETURN (@judgecode)
>if @module='LL'
>        SELECT @judgecode= ll_judge FROM locallaw
>        WHERE keyident = @keyident
>RETURN (@judgecode)
>if @module='CV'
>        SELECT @judgecode=civ_judge FROM civil
>        WHERE keyident = @keyident
>RETURN (@judgecode)
>if @module='CRM'
>        SELECT @judgecode=crm_judge FROM criminal
>        WHERE keyident = @keyident
>RETURN (@judgecode)
>if @module='SC'
>        SELECT @judgecode=sc_judge FROM smallclaims
>        WHERE keyident = @keyident
>RETURN (@judgecode)
>end
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform