Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 column value based on a formula

Author  Topic 

BendJoe
Posting Yak Master

128 Posts

Posted - 2007-11-15 : 15:41:35
I am trying to do the following.
While inserting a record into a table I need one field to be created based on a stored procedure output.The stored procedure will create something like this, "XX-mm-yyyy-incremental number which resets to zero at the end of every month". All other field except the Identity field and the above mentioned storeproc generated field will be inputted manually. How can I do this?
Thanks
Hope my question is clear enough.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-15 : 15:43:59
well you could put the stored procedure output into a temp table and select from there, or you could add an output parameter to your sproc and use that.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

BendJoe
Posting Yak Master

128 Posts

Posted - 2007-11-15 : 16:29:34
Assuming that I use the second approach ie, specifying an output parameter for my stored proc. How will I include the stored proc output to my Insert Command.
My Insert Command is
INSERT INTO [Table] ([CODE], [TYPE], [ID]) VALUES (@CODE, @TYPE, @ID) Here CODE is the field which should be the output of the my Stored Proc.
Thanks
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-15 : 16:51:07
declare @CODE varchar(50) -- <- change to your datatype here
exec yourSproc @CODE out
INSERT INTO [Table] ([CODE], [TYPE], [ID]) VALUES (@CODE, @TYPE, @ID)

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -