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.
Author |
Topic |
jp2code
Posting Yak Master
175 Posts |
Posted - 2009-01-07 : 16:28:55
|
I've got my stored procedure (returns the test pressure number from the Test_Results field) tested in Query Analyzer, but it won't allow me to return a value.The rest of the procedure seems to execute without problems, though, so I plugged it into my new function in SQL. I clicked "Check Syntax" and got a go, but whenever I try to save the function, I get this:quote: Error 21001: [SQL-DMO]Stored procedure definition must include name and text (for Standard StoredProcedure) or libraryname (for Extended StoredProcedure).
What does this mean? How do I fix it?Create Function dbo.sp_GetUlTestPressure(@serial_number varchar(20))returns intasbegindeclare @coilType varchar(20), @item varchar(255), @test_result varchar(255)declare @testPressure int, @index int, @count int, @bool intset @testPressure=-1set @count=0select @test_result=test_result from acp_parts where (system_id like '%label%') and (serial_number like @serial_number)set @index=CharIndex(',', @test_result)while (1 < @index) begin set @item=SubString(@test_result, 1, @index - 1) -- gets the leftmost item if (@count=5) begin-- 0:WO&PartNo;-- 1:GrpNum;-- 2:RowsDeep;-- 3:HeaderRows;-- 4:CoilType;-- 5:Pressure if (IsNumeric(@item)=1) begin set @bool=Cast(@item as int) set @testPressure=Cast(@item as int) end end else if (@count=4) begin if (CharIndex(',', @test_result)=0) begin set @coilType=@test_result select top 1 @testPressure=testPressure from TestPressures where coilType=@coilType end end else begin set @test_result=LTrim(SubString(@test_result, @index + Len(','), Len(@test_result))) set @index=CharIndex(',', @test_result) set @count=@count+1 endendreturn @testPressureend Avoid Sears Home Improvement |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-07 : 16:39:05
|
Why are you creating Function with (Sp_getUI)? It is generally used for System sp and search in Master database for it. Change Name to UDF? |
|
|
jp2code
Posting Yak Master
175 Posts |
Posted - 2009-01-07 : 16:41:58
|
Ok, I changed that first line to read:Create Function dbo.udf_GetUlTestPressure(@serial_number varchar(20)) Still, if I try to save it, I get the Error 21001 listed above.What causes this? Avoid Sears Home Improvement |
|
|
jp2code
Posting Yak Master
175 Posts |
Posted - 2009-01-07 : 16:57:36
|
Kept searching and I found the answer - probably what sodeep was trying to tell me, but I didn't understand it fully.What I was doing was trying to create this in the Stored Procedures section of SQL Server.Instead, I had to create this in the User Defined Functions section of SQL Server.The new Function saved without any problems this way. Avoid Sears Home Improvement |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|