» Default Input from variable
Default Input from variable
|September 15, 2014
Posted by forumadmin
I’m trying to call a table valued function with some variable inputs. However, I’d like to use the function’s
default value if the calling script doesn’t set the input value.
So, assume I have the function (yes, this is a silly function)
create function dbo.testing(@countTo int=10)
returns @output table(num int)
declare @i int
while @i < @countTo
insert into @output(num)
Then, I could setup a variable for the input:
declare @stop int
select * from dbo.testing(@stop)
@stop is left as
null, I’d like to use the
default value, but it will just use
null (which returns nothing…). Essentially, I want the following to work:
select * from dbo.testing(isnull(@stop,default))
But it just returns the error:
Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword
Is there anyway to do this without modifying the function?
More Related Questions
- How to SELECT * INTO [temp table] FROM [stored procedure] How do I do a SELECT * INTO [temp table] FROM [stored procedure]? Not FROM [Table] and without defining [temp table]?
Select all data from BusinessLine into tmpBusLine works fine.
- How do I insert multiple rows WITHOUT repeating the "INSERT INTO dbo.Blah" part of the statement? I know I've done this before years ago, but I can't remember the syntax, and I can't find it anywhere due to pulling up tons of help docs and articles about "bulk imports".
Here's what I […]
- sp_replmonitorsubscriptionpendingcmds into a table [How2] Im looking to making a job that will tell me the number of pending cmd's on the replication,
Im using sp_replmonitorsubscriptionpendingcmds and im trying my best to put it into a […]
- Trigger exits on first failed insert and cant set xact_abort OFF in SQL Server 2000 I have built a simple database to run on SQL Server 2005 and now need to get it working on SQL Server 2000. The aim is as follows:
I receive a daily data feed containing ~5k records into […]
- How do I create unique constraint that also allows nulls in sql server Adding a column to table, and I want a unique constraint, so the column will insert GUID's, but to allow for existing data before column was added, I need to allow for NULL's in the […]
- SQL Server – pull X random records per state I have a table with records for each zip code in the united states. For the purposes of displaying on a map, I need to select X random records per state. How would I go about doing […]
- Get top 1 row of each group I have a table which I want to get the latest entry for each group. Here's the table:
|ID| DocumentID | Status | DateCreated |
| 2| 1 | S1 | […]
- Delete duplicate records from a SQL table without a primary key I have the below table with the below records in it
create table employee
insert into employee values(1, 'Jack', […]
- SQL update query using joins I have to update a field with a value which is returned by a join of 3 tables.
,im.sku as iSku
,gm.SKU as GSKU
,mm.ManufacturerId as ManuId
- How can I do an UPDATE statement with JOIN in SQL? I need to update this table in MS SQL Server 2005 with data from its 'parent' table, see below: