hi,like this? IF (@RateLevel1 IS NOT NULL) and (@RateLevel2 IS NOT NULL) ... begin raiserror 'parameters null value!' return 1 --fail end else begin insert into ... return 0 --success end
yahao
Posts
-
Stored Procedures - Validating Variables -
Getting Top 10 results per month/yearA non-clever method is to use temp table instead of a single sql script. :p
-
SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specifiedor try to directly connect remote server use IP rather than use machine name. this is the fun of resolve problem.:)
-
sql 2000 installing problemplz see sqlsetup.log for detail information in %windows% folder.
-
SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specifiedtry to config an alias for "DEVSQL" with sql server client network utility. ps: DEVSQL <=> IP on Lan i have only use SSPI in same machine,not lan or internet yet.:p
-
stored-proc questionyou can use sql server agent.:)
-
writing a stored procedure which makes multiple insertions-- need helpGood style: SELECT @availableQty = ( SELECT COUNT(*) As AvailableQty FROM vu_unsoldproducts GROUP BY serial, prodlineid, manid, modelid HAVING prodlineid = @prodLineID AND manid = @manid AND modelid = @modelID AND UPPER(serial) = UPPER(@Serial) ) Bad style: Select @availableQty = (select count(*) AvailableQty FROM vu_unsoldproducts Group by serial, prodlineid, manid, modelid HAVING prodlineid = @prodLineID AND manid = @manid AND modelid = @modelID AND UPPER(serial) = UPPER(@Serial))
-
writing a stored procedure which makes multiple insertions-- need helphi! I wrote sql server stored procedure since 2002,as a matter of experience,the best way to reduce bugs and errors is keep good habit for coding. for example,code with EditPlus text-editor rather than sql server query analyzer,and use the syntax file & auto-completion for *.sql file type. of course,one important factor is has clear structure of application,and then,produce high-quality code.:) there is some code of mine: /* '############################################################################## '## Copyright (C) 1998-2006 Yahao SoftWorks '## '## PROJ: FFS '## SUBJ: get common present data '## '## Code by Yahao '############################################################################## '## C/U-Date: 2006-10-09 */ -- Remove the existing Stored Procedure -- if (exists (select * from sysobjects where name = 'usp_m_getcPresentDetailData' and type = 'P')) drop proc usp_m_getcPresentDetailData go CREATE PROCEDURE usp_m_getcPresentDetailData ( ---- In: op id ---- @inCmdID smallint, ---- In: obj id ---- @inOpItemID int, ---- In: obj name ---- @inOpItemName varchar(60), ---- Out: record amount ---- @otcPresentAmount int OUTPUT, ---- Ret ---- @ReturnValue int OUTPUT ) WITH ENCRYPTION AS SET NOCOUNT ON DECLARE @intRetValue As int,@intErrCode As int DECLARE @intcPresentAmount As int IF @@NESTLEVEL = 1 BEGIN SET @ReturnValue = 99 RAISERROR ('illegal call',16, 1) RETURN END ---- var init ---- SET @intErrCode = 0 SET @intcPresentAmount = 0 ---- RS1: present data ---- SELECT PresentName, StockAmount, AvgStockPrice, OptionSet, CatID, StockStatusTID, Remark, CreateOn, Status FROM onenb_shop.dbo.CommonPresentData WHERE PresentID = @inOpItemID ---- return data ---- SET @otcPresentAmount = @intcPresentAmount SET @ReturnValue = 0 SET NOCOUNT OFF
-
SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specifiedif connect to server on otder machine,use machine-IP\instance-id,otherwise use "(local)". btw,maybe need config the client-network information with SQL Server Client Network Utility,the server-ip and port,etc.
-
In Search Of A Good Query Tooltry these products: http://www.embarcadero.com/index.html[^]
-
How is this possible? Plz help......use "Access Password Recovery" soft can reset your passowrd,and then enjoy it! to get soft,use the key "ms access password" search google.com :)
-
writing a stored procedure which makes multiple insertions-- need helpthere has two mistake in your code: 1.missing a right bracket at the end of "Select @avialbleQty = (..." 2.the var @availableQty is not equal definition :) The code after DEBUG: CREATE PROCEDURE dbo.BranchBillDetailInsertCombo ( @BillID numeric(18), @Quantity int, @Serial varchar(30), @prodLineID numeric(18), @ManID numeric(18), @ModelID numeric(18), @PresentAT numeric(18), @Error_code INT OUTPUT ) AS DECLARE @counter int DECLARE @availableQty int DECLARE @PurchID numeric(18) DECLARE purch_cursor CURSOR FOR SELECT purchid FROM vu_unsoldproducts WHERE prodLineID = @prodLineID AND Manid = @Manid AND ModelID = @ModelID AND Upper(Serial) = Upper(Serial) AND presentAT = @presentAT Select @availableQty = (select count(*) AvailableQty FROM vu_unsoldproducts Group by serial, prodlineid, manid, modelid HAVING prodlineid = @prodLineID AND manid = @manid AND modelid = @modelID AND UPPER(serial) = UPPER(@Serial)) SET @Error_code = 0 -- means there is no error in executing the stored procedure IF @Quantity >@availableQty BEGIN SET @ERROR_CODE = -1 --return -- dubious statement... I dont know the syntax for that. END ELSE BEGIN OPEN purch_cursor FETCH NEXT FROM purch_cursor INTO @PurchID Insert INTO branchBillDetail(BillID, purchID) Values (@BillID, @purchID) SET @counter = 1 WHILE (@@FETCH_STATUS = 0) OR (@Counter < @Quantity) BEGIN SET @counter = @counter + 1 -- @counter++ FETCH NEXT FROM purch_cursor INTO @PurchID Insert InTo branchBillDetail(BillID, purchID) Values (@BillID, @purchID) END CLOSE purch_cursor DEALLOCATE purch_Cursor END