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
 How to call stored procedure in table???

Author  Topic 

Manoool
Starting Member

6 Posts

Posted - 2007-11-12 : 10:29:15
Hi.....

I have problem and I need your help



I stored a procedure in the Projects Folder in my computer

and I want to return the procedure result in a column inside table

How I can do that?????????



thank you

anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-12 : 10:30:50
is the procedure result a single value?
Go to Top of Page

Manoool
Starting Member

6 Posts

Posted - 2007-11-12 : 11:31:31


this is the procedure



create proc makeTestKey(@courseNumber int) as

begin

insert into test(a2) values(right( replicate('0', 7) + convert(char(6), convert(int, Year(GetDate()) % 2000 * 10000 + @courseNumber)), 7))

end



where the courseNumber is column in the test table
and I want the result to be store back in the column a2 in the same table

but I do't how to do this and
I hope to help me
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-12 : 11:39:46
CourseNumber is a column name in your destination table? and you want column a2 to be updated with that..

WHat you are asking doesn't make a whole lot of practical sense, but to update column a2 with the formula



Update [TestTable]
Set a2 = right( replicate('0', 7) + cast(Year(GetDate()) % 2000 * 10000 + @courseNumber as varchar), 7))









Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

Manoool
Starting Member

6 Posts

Posted - 2007-11-12 : 13:10:44

but ,

where should I put this formula????????

Update [TestTable]
Set a2 = right( replicate('0', 7) + cast(Year(GetDate()) % 2000 * 10000 + @courseNumber as varchar), 7))

in query???? or formula property????
and if I should put it in query,
how can I call this query such that
each time I enter data in the test table
the a2 column will contain this value????????

please help me
because I lost the hope to solve it.....

thank
Go to Top of Page

anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-12 : 13:39:39
if one coursenumber will only ever have one testkey and the formula to generate that testkey is NEVER expected to change, then you can have a table with columns, coursenumber & coursedate, plus a calculated column (testkey?) as the formula above using coursedate not getdate. does that answer your question?
Go to Top of Page

Manoool
Starting Member

6 Posts

Posted - 2007-11-12 : 13:55:21
No

the test key which is the a2 will be change with each entry
because coursenumber is an identity


I will explain the issue with more details

I want to create primary key from 6 integer digits that contain two part

the first part is the first two number from the year

the second part is auto generation number from 0000 to 9999

for example: in this year "2007"

the number will be from 070000 to 079999

and I do not know how I can do this????????


and some person give me this procedure that I mention before
to solve this
but I did not how to use it!!!!!!!

if have a better solution
please help me

I am waiting
Go to Top of Page

anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-12 : 14:50:57
can courseNumber 99 have a testkey 070000 if courseNumber 55 has a testkey 070000? or should it testkey be unique for every courseNumber?
Go to Top of Page
   

- Advertisement -