Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return a scalar value from SQL Server 2000 UDF
Message
From
26/09/2005 12:01:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01053027
Message ID:
01053093
Views:
11
>Hello All, could someone please help me out here, how do I call the SQL Server 2000 function below using C# and ADO.Net, I've tried treating it like a stored proc but without success
>
>
>
>FUNCTION ResolveToMaster (@cUnknown varchar(10))
>RETURNS varchar(10)
>AS
>begin
>
>
>declare @MasterRef varchar(10)
>
>select @MasterRef = null
>
>
>select  @MasterRef = (Select Distinct MasterRef from Claim where MasterRef =  @cUnknown)
>
>if @MasterRef is null
>begin
>	select  @MasterRef = (Select Distinct MasterRef from  Claim where CustomerRef =  @cUnknown)
>	
>end
>
>if @MasterRef is null
>	begin
>		select  @MasterRef = (Select Distinct MasterRef from Claim where ClaimRef =  @cUnknown)
>		
>	end
>
>
>Return @MasterRef
>end
>
>
>
>
>what I'm trying to achieve here is, to allow a user to enter either of three different numbers and resolve the number to a master reference ( their idea not mine !?? )

Pete,
Assuming your function is right and working:
 SqlConnection sConn = new SqlConnection 
           ("Data Source=server;integrated Security=sspi;initial catalog=myDatabase;");

 SqlCommand cmd = new SqlCommand("select dbo.ResolvetoMaster(@cUnknown)", sConn);
 SqlParameter iv = cmd.Parameters.Add("@cUnknown", SqlDbType.VarChar, 10);

 sConn.Open();
 iv.Value = "ValToCheck";
 string retVal = (string)cmd.ExecuteScalar();
 sConn.Close();
There are other ways too.
PS: It looks like you actually wanted to create a stored procedure.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform