| Author |
Topic |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 14:03:29
|
| alter procedure dbo.[sp_update](@login_name varchar(50))asbeginselect top 1 delivery_date from tbl_master_product where client_name=@login_nameendbeginif(delivery_date!=getdate())beginreturn 1endelsebeginreturn 0endendI have errorMsg 207, Level 16, State 1, Procedure sp_update, Line 10Invalid column name 'delivery_date'. |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 14:04:23
|
| Then how to use the selected value for checking process |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 14:09:34
|
| Tnx for response,I tried this but i received this errorMsg 156, Level 15, State 1, Procedure Update, Line 5Incorrect syntax near the keyword 'top'.Msg 102, Level 15, State 1, Procedure Update, Line 11Incorrect syntax near '0'. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 14:20:20
|
| One small doubt .. What is the use for <> this symbol..I need to check only the current date present or not .. If not present I will update it..So only I am using return statement.. Tnx for the nice help.. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 14:23:28
|
| Thank you for your help.. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-09-23 : 14:29:30
|
and returning a value is NOT a good idea...unless M$ changed it...the return value has the potential to be overlayed by SQL Server itselfAnd TOP without an ORDER BY is meaninglessWhat do you really want to know?In this Case it seems like if ANYTHING EXISTS for the login from the mast product table means "TRUE"Is that what you want?IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[dbo.usp_SEL_delivery_date]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[dbo.usp_SEL_delivery_date]GOCREATE PROC dbo.usp_SEL_delivery_date @login_name varchar(50) , @delivery_date datetime OUTPUT , @rc int OUTPUT, @Error int OUTPUT, @Error int OUTPUT, @Error_Message varchar(255) OUTPUTASSET NOCOUNT ONDECLARE @Error_Type int SELECT @delivery_date = TOP 1 delivery_date FROM tbl_master_product WHERE client_name=@login_nameORDER BY delivery_date DESCSELECT @Error = @@ERROR, @Rowcount = @@ROWCOUNT IF @error <> 0 BEGIN SELECT @Error_Type = 50001, @rc = -1 GOTO usp_SEL_delivery_date_Err ENDIF @rowcount = 0 BEGIN SELECT @Error_Type = 50002, @rc = 1 , @Error_Message = 'Login: "' + @login_name + '" returned 0 Rows' GOTO usp_SEL_delivery_date_Err ENDusp_SEL_delivery_date_Err_Exit:SET NOCOUNT OFF RETURNusp_SEL_delivery_date_Err: ROLLBACK TRAN IF @Error_Type < 50000 RAISERROR @Error_Type @Error_Message GOTO usp_INS_SERVICE_INFO_BY_SERVICE_SUB_GROUP_ExitGOGRANT EXEC ON [usp_SEL_delivery_date] TO [Some_Role]GO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspx |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 14:40:06
|
| Nice thought ...I learned some more good ideas from your post.. Tnx for it |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 14:41:34
|
| When executing the above procedure i received the following errorsMsg 134, Level 15, State 1, Procedure usp_SEL_delivery_date, Line 5The variable name '@Error' has already been declared. Variable names must be unique within a query batch or stored procedure.Msg 156, Level 15, State 1, Procedure usp_SEL_delivery_date, Line 12Incorrect syntax near the keyword 'TOP'.Msg 137, Level 15, State 1, Procedure usp_SEL_delivery_date, Line 17Must declare the scalar variable "@Rowcount".Msg 137, Level 15, State 2, Procedure usp_SEL_delivery_date, Line 25Must declare the scalar variable "@rowcount".Msg 137, Level 15, State 1, Procedure usp_SEL_delivery_date, Line 28Must declare the scalar variable "@Error_Message".Msg 137, Level 15, State 2, Procedure usp_SEL_delivery_date, Line 40Must declare the scalar variable "@Error_Message". |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 18:28:46
|
| tnx for response |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-09-23 : 18:40:10
|
Just an FYI, it's good practice to use SET to assign your variables to avoid unexpected results from a SELECT that returns more than more row. (obviously that would be a logical error, but they can be the hardest to find). For example:DECLARE @Foo INTDECLARE @Bar TABLE (ID INT, Val INT)INSERT @Bar (ID, Val)VALUES(1, 1),(2, 1),(3, 2),(4, 2)-- SucceedsSELECT @Foo = ID FROM @Bar WHERE Val = 1SELECT @Foo-- FailsSET @Foo = (SELECT ID FROM @Bar WHERE Val = 2)SELECT @Foo The second method will fail, so you know that you are returning more than one one tuple and not assigning a random row (like the first assignment). |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-23 : 18:46:39
|
| I got it thank you.. |
 |
|
|
|