Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default value from stored procedure

Status
Not open for further replies.

anonim1

Programmer
Dec 10, 2004
108
US
I have a stored procedure named GenerateRandomString, which takes an output parameter and returns a random string of set length.

I have a table in my database where I would like to automatically insert the string returned by the stored procedure as a default value for one of the columns of the table. Unfortunately, I cannot figure out what the syntax is to call this stored procedure for a default value.

Any ideas?
 
You can't call a procedure for a default value. Convert the procedure to a function. You can use functions as a default value. Then in order to keep the procedure working, have the procedure call the function.

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
You can't have default values for stored procedure parameters?
 
mrdenny,

Thanks for the quick response! Can you help me convert it to a function? I am not familiar with the syntax. Here is my stored procedure:

Code:
CREATE PROCEDURE [dbo].[GetRandomGuid] AS
DECLARE @guid varchar(30)
EXEC dbo.GenerateRandomString 1,1,1,null,30,@guid OUT
PRINT @guid

Thanks for your help!
 
You'll need to convert GenerateRamdonString into a function. Functions can't call procedures.

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top