473,320 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Variable Paramters to Functions

From previous postings I have read it seems that I cannot create a
function that accepts a variable list of parameters. Seems that SQL
Server does not support this.

A few questions:
Is this true?

What is a workaround?

Then how does the function COALESCE do it?
Cut and pasted from online books:

Syntax
COALESCE ( expression [ ,...n ] )

Arguments
expression

Is an expression of any type.

n

Is a placeholder indicating that multiple expressions can be
specified. All expressions must be of the same type or must be
implicitly convertible to the same type.
Jul 20 '05 #1
3 2510
> Is this true?
It's true that all parameters must be specified each time a User Defined
Function is called. But the parameter values can include NULL or DEFAULT
values.
What is a workaround? That depends on your requirements. Put your parameter values in a table and
use a SELECT statement to calculate the result might be one solution -
possibly a more efficient solution than a UDF since UDF calls are relatively
slow. If you have a particular requirement in mind then give some details
and see if someone can help.
Then how does the function COALESCE do it?

COALESCE is a system function not a UDF. UDFs are created in TSQL using the
CREATE FUNCTION syntax. System functions are not.

--
David Portas
------------
Please reply only to the newsgroup
--
Jul 20 '05 #2
Yes, functions doesn't accept variable list of params.......this is
true!

I faced this problem previously and i thought of two solutions:

1. use a temporary table, enter all params, read them from function
2. concat all params in a string separated by comma or some separator,
so some string manipulation in the function, extract all and use it.

-Hayat
www.mysticssoft.com

Ja*******@hotmail.com (Jason) wrote in message news:<f0**************************@posting.google. com>...
From previous postings I have read it seems that I cannot create a
function that accepts a variable list of parameters. Seems that SQL
Server does not support this.

A few questions:
Is this true?

What is a workaround?

Then how does the function COALESCE do it?
Cut and pasted from online books:

Syntax
COALESCE ( expression [ ,...n ] )

Arguments
expression

Is an expression of any type.

n

Is a placeholder indicating that multiple expressions can be
specified. All expressions must be of the same type or must be
implicitly convertible to the same type.

Jul 20 '05 #3
Jason (Ja*******@hotmail.com) writes:
From previous postings I have read it seems that I cannot create a
function that accepts a variable list of parameters. Seems that SQL
Server does not support this.


Depends on what you want to do, but if you want to submit a list of
scalar values to work on, you can put in a comma-separated string
and unpack into a table variable in the function. As for unpacking
that list, see here for a sample of such functions:
http://www.algonet.se/~sommar/arrays...html#iterative.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
7
by: |-|erc | last post by:
<?php if ((!isset($s)) && (!isset($msg))) { echo("<table> .... I want some pictures displayed on the main page if its a new visit, but when they search and the url bar changes its skips...
5
by: Jim Banks | last post by:
Greetings I'm opening a pop up window with a html form, (in one document) and I want to pass a variable to the html form called from the hyperlink. Here's the code I'm using to pop up the...
13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
7
by: PL | last post by:
I want to dynamicaly create variable and assigned it a particular name, for exemple: foreach (FileInfo FI in ArrayOfFiles) { string FI.Name = "AValueWhoDoesntMatter" } Of course, this...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
5
by: K Viltersten | last post by:
I discovered that when requested http://localhost:52698/ws3/page.aspx and issued a call Response.Write(Request.Params.Count); i got 50 parameters in count. When i actually added some as...
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.