November 1, 2013 at 11:31 pm
I have written a stored procedure like
USE [nxnv1_temp]
GO
/****** Object: StoredProcedure [dbo].[SP_CONSULTATION_DETAILS1] Script Date: 11/02/2013 10:06:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_CONSULTATION_DETAILS1]
@AGE numeric(3, 0),
@date DATE ,
@time TIME,
@SEX varchar(1),
@AMOUNT numeric(6, 2)
AS
BEGIN
SELECT AMOUNT=
(CASE
WHEN DATENAME(DW, @date) = 'Sunday' THEN
CASE
WHEN @AGE <= 10 THEN 300
ELSE 700
END
WHEN DATENAME(DW, @date) = 'Saturday' THEN
CASE
WHEN @AGE <= 10 THEN 300
ELSE 500
END
ELSE
CASE
WHEN @time < '06:00' OR @time > '18:00' THEN
CASE
WHEN @AGE <= 10 THEN 200
ELSE 500
END
ELSE
CASE
WHEN @AGE < 5 THEN 0
WHEN @AGE >= 5 AND @AGE <= 10 THEN 100
ELSE 200
END
END
END) FROM MASTEROPCONSAMT
END
i want to set the values for amount field. is it need to join the two tables? please suggest me or help me to close this issue
i have a tables like below
registration table:-
PRNOnumeric(11, 0)(primary key)
REGFROMvarchar(10)
REGDATEdatetime
FIRSTNAMEvarchar(60)
RELATIONCODEvarchar(3)
GUARDIANNAMEvarchar(50)
DOBdatetime
AGEnumeric(3, 0)
AGETYPEvarchar(6)
SEXvarchar(1)
ORGCODEvarchar(10)
BGROUPvarchar(3)
RHTYPEvarchar(3)
HNOvarchar(50)
STREETvarchar(50)
LOCvarchar(50)
AREACODEnumeric(6, 0)
PHONERvarchar(15)
PHONEOvarchar(15)
PAGERvarchar(15)
MOBILEvarchar(15)
FAXvarchar(15)
EMAILvarchar(50)
IDENTIFICATIONMARKSvarchar(200)
REFDOCTCODEvarchar(10)
PAYTYPEvarchar(11)
USERIDvarchar(50)
SENTnchar(1)
REMARKSvarchar(50)
ReligionCodenumeric(2, 0)
MIDDLENAMEvarchar(20)
LASTNAMEvarchar(30)
TITLEvarchar(10)
and
opconsamt table:-
DOCCDvarchar(6)
CONSTYPEvarchar(3)
TARIFFCDvarchar(10)
VISITNOnumeric(2, 0)
AMOUNTnumeric(6, 2)
VALIDDAYSnumeric(3, 0)
MAXVISITSnumeric(2, 0)
COMPCODEvarchar(10)
FOLLOWUPAMTnumeric(6, 2)
November 3, 2013 at 12:46 pm
I really have no idea what you are asking, since your procedure doesn't reference the tables you mention at all.
Do you mean you want to set the amount variable? Or are you trying to update one or the other of the tables you mentioned with the value you calculate?
In general, when posting a question, you'll get much better quality answers if you put in the time to create a script that sets up the problem, and give an example of the result you want to see based on the sample data that you provide.
Dan Guzman - Not the MVP (7/22/2010)
All questions have to be prefaced by Server version and 'according to MS Docs' or 'my own personal opinion based on how much detail I felt like digging into at the time.'
November 4, 2013 at 8:32 am
Please keep to one thread for all questions. There are at least three for this one.
Here is my response from one of the others. Let's use this on as the "main" thread.
Sean Lange (11/4/2013)
I started by formatting your proc so we can read it. If you post this stuff in a code block (using IFCode shortcuts on the left when posting) it will help maintain your formatting.
ALTER PROCEDURE [dbo].[SP_CONSULTATION_DETAILS1] @AGE NUMERIC(3, 0)
,@date DATE
,@time TIME
,@SEX VARCHAR(1)
,@AMOUNT NUMERIC(6, 2)
AS
BEGIN
SELECT AMOUNT = (
CASE
WHEN DATENAME(DW, @date) = 'Sunday'
THEN CASE
WHEN @AGE <= 10
THEN 300
ELSE 700
END
WHEN DATENAME(DW, @date) = 'Saturday'
THEN CASE
WHEN @AGE <= 10
THEN 300
ELSE 500
END
ELSE CASE
WHEN @time < '06:00'
OR @time > '18:00'
THEN CASE
WHEN @AGE <= 10
THEN 200
ELSE 500
END
ELSE CASE
WHEN @AGE < 5
THEN 0
WHEN @AGE >= 5
AND @AGE <= 10
THEN 100
ELSE 200
END
END
END
)
FROM MASTEROPCONSAMT
END
It is impossible to determine what you are trying to do here. The biggest issue I see is that your stored proc is not filtering which row from MASTEROPCONSAMT. It is going to set the value for Amount for only 1 row in your table. If could post ddl, sample data and desired output for the two tables we can help.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply