I need a stored procedure that include dynamic where clause. so I
created these two sp. GetCampaigns calls Checkvalues sp to complete
where clauseb but it doesn't work. any idea ?
CREATE PROCEDURE GetCampaigns (@.CampaignTypeId int,@.CardTypeId int)
AS
SELECT Campaigns.* FROM Campaigns
WHERE (CheckValues 'Campaigns.CampaignTypesId',@.CampaignTypeId) AND
(CheckValues 'Campaigns.CardTypesId',@.CardTypeId)
GO
CREATE PROCEDURE CheckValues(@.InitialStr nvarchar(30),@.Type int)
AS
IF((@.Type = 1) OR (@.Type = 0))
SELECT @.InitialStr + '!=0'
ELSE
SELECT @.InitialStr + '=' + @.Type
GOUse a function and not a procedure for CheckValues
Daniel EYER
"ONEY" <ozcankanbur@.gmail.com> a crit dans le message de
news:c16976dd.0502220317.735fa507@.posting.google.com...
> I need a stored procedure that include dynamic where clause. so I
> created these two sp. GetCampaigns calls Checkvalues sp to complete
> where clauseb but it doesn't work. any idea ?
>
> CREATE PROCEDURE GetCampaigns (@.CampaignTypeId int,@.CardTypeId int)
> AS
> SELECT Campaigns.* FROM Campaigns
> WHERE (CheckValues 'Campaigns.CampaignTypesId',@.CampaignTypeId) AND
> (CheckValues 'Campaigns.CardTypesId',@.CardTypeId)
> GO
> CREATE PROCEDURE CheckValues(@.InitialStr nvarchar(30),@.Type int)
> AS
> IF((@.Type = 1) OR (@.Type = 0))
> SELECT @.InitialStr + '!=0'
> ELSE
> SELECT @.InitialStr + '=' + @.Type
> GO|||Oney
Don't use dynamic WHERE condition ,instead read this great article
http://www.sommarskog.se/dyn-search.html
"Daniel Eyer" <daniel.eyer@.free.fr> wrote in message
news:421b2391$0$1226$8fcfb975@.news.wanadoo.fr...
> Use a function and not a procedure for CheckValues
> Daniel EYER
> "ONEY" <ozcankanbur@.gmail.com> a crit dans le message de
> news:c16976dd.0502220317.735fa507@.posting.google.com...
>sql
Showing posts with label include. Show all posts
Showing posts with label include. Show all posts
Tuesday, March 27, 2012
Saturday, February 25, 2012
Calender in Reports 2K
One of my report has 2 input variables, StartDate and EndDate. Is that
possible that I can include a calender control in the report interface such
that user can choose the date rather than typing it in?
I come to know that :
That is not an option today (sure would be a nice improvement). If you
need this then you need to create your own web page and then integrate with
RS using URL or SOAP.
If it is so then can anyone help me with example how to use it.
will be very helpful if i get any attachment.
Thanks & Regards
Labhesh Shrimali
Bangalore -Cross posting to microsoft.public.sqlserver.reportingsvcs since this
question isn't related to security.
Hope this helps.
Dan Guzman
SQL Server MVP
"Labhesh Shrimali - Bangalore"
<LabheshShrimaliBangalore@.discussions.microsoft.com> wrote in message
news:86E50086-C732-4B90-B9F9-881A9EC0FD42@.microsoft.com...
> One of my report has 2 input variables, StartDate and EndDate. Is that
> possible that I can include a calender control in the report interface
> such
> that user can choose the date rather than typing it in?
> I come to know that :
> That is not an option today (sure would be a nice improvement). If you
> need this then you need to create your own web page and then integrate
> with
> RS using URL or SOAP.
> If it is so then can anyone help me with example how to use it.
> will be very helpful if i get any attachment.
> Thanks & Regards
> Labhesh Shrimali
> Bangalore -
>
possible that I can include a calender control in the report interface such
that user can choose the date rather than typing it in?
I come to know that :
That is not an option today (sure would be a nice improvement). If you
need this then you need to create your own web page and then integrate with
RS using URL or SOAP.
If it is so then can anyone help me with example how to use it.
will be very helpful if i get any attachment.
Thanks & Regards
Labhesh Shrimali
Bangalore -Cross posting to microsoft.public.sqlserver.reportingsvcs since this
question isn't related to security.
Hope this helps.
Dan Guzman
SQL Server MVP
"Labhesh Shrimali - Bangalore"
<LabheshShrimaliBangalore@.discussions.microsoft.com> wrote in message
news:86E50086-C732-4B90-B9F9-881A9EC0FD42@.microsoft.com...
> One of my report has 2 input variables, StartDate and EndDate. Is that
> possible that I can include a calender control in the report interface
> such
> that user can choose the date rather than typing it in?
> I come to know that :
> That is not an option today (sure would be a nice improvement). If you
> need this then you need to create your own web page and then integrate
> with
> RS using URL or SOAP.
> If it is so then can anyone help me with example how to use it.
> will be very helpful if i get any attachment.
> Thanks & Regards
> Labhesh Shrimali
> Bangalore -
>
Calender
One of my report has 2 input variables, StartDate and EndDate. Is that
possible that I can include a calender control in the report interface such
that user can choose the date rather than typing it in?No. That is not an option today (sure would be a nice improvement). If you
need this then you need to create your own web page and then integrate with
RS using URL or SOAP.
Bruce L-C
"Frank" <nospam@.nospam.org> wrote in message
news:eWgWxGxhEHA.3944@.tk2msftngp13.phx.gbl...
> One of my report has 2 input variables, StartDate and EndDate. Is that
> possible that I can include a calender control in the report interface
such
> that user can choose the date rather than typing it in?
>
>
possible that I can include a calender control in the report interface such
that user can choose the date rather than typing it in?No. That is not an option today (sure would be a nice improvement). If you
need this then you need to create your own web page and then integrate with
RS using URL or SOAP.
Bruce L-C
"Frank" <nospam@.nospam.org> wrote in message
news:eWgWxGxhEHA.3944@.tk2msftngp13.phx.gbl...
> One of my report has 2 input variables, StartDate and EndDate. Is that
> possible that I can include a calender control in the report interface
such
> that user can choose the date rather than typing it in?
>
>
Sunday, February 19, 2012
Calculation including previous record value
Hi,
How can I do calculation on the SQL Server that would include previous
record.
e.g.
a,b field in the table
if a is first record, then a= b
else
a = a(previous record value)+ b
Thank you for help
Schapopa
*** Sent via Developersdex http://www.examnotes.net ***Hi
CREATE TABLE #Test (col1 INT NOT NULL PRIMARY KEY, col2 INT NOT NULL)
INSERT INTO #Test VALUES (1,100)
INSERT INTO #Test VALUES (2,500)
INSERT INTO #Test VALUES (3,800)
INSERT INTO #Test VALUES (4,900)
SELECT *,(SELECT SUM(col2) FROM #Test as q
WHERE m.col1 >= q.col1 )AS total
FROM #Test AS m
<schapopa> wrote in message news:u7kCv1lRGHA.336@.TK2MSFTNGP12.phx.gbl...
> Hi,
> How can I do calculation on the SQL Server that would include previous
> record.
> e.g.
> a,b field in the table
> if a is first record, then a= b
> else
> a = a(previous record value)+ b
> Thank you for help
> Schapopa
>
>
> *** Sent via Developersdex http://www.examnotes.net ***
How can I do calculation on the SQL Server that would include previous
record.
e.g.
a,b field in the table
if a is first record, then a= b
else
a = a(previous record value)+ b
Thank you for help
Schapopa
*** Sent via Developersdex http://www.examnotes.net ***Hi
CREATE TABLE #Test (col1 INT NOT NULL PRIMARY KEY, col2 INT NOT NULL)
INSERT INTO #Test VALUES (1,100)
INSERT INTO #Test VALUES (2,500)
INSERT INTO #Test VALUES (3,800)
INSERT INTO #Test VALUES (4,900)
SELECT *,(SELECT SUM(col2) FROM #Test as q
WHERE m.col1 >= q.col1 )AS total
FROM #Test AS m
<schapopa> wrote in message news:u7kCv1lRGHA.336@.TK2MSFTNGP12.phx.gbl...
> Hi,
> How can I do calculation on the SQL Server that would include previous
> record.
> e.g.
> a,b field in the table
> if a is first record, then a= b
> else
> a = a(previous record value)+ b
> Thank you for help
> Schapopa
>
>
> *** Sent via Developersdex http://www.examnotes.net ***
Thursday, February 16, 2012
Calculating Yield
I have a database that will have a date and a Judgement in it. There 2
possible judgements, GOOD and BAD.
I can filter the data to include just 1 month data, for example, Feb's data
from 02/01/06 to 02/28/06.
I would like to get output that looks like the following:
DATE YIELD
1 .90
2 .98
3 .80
4 .79
5 .60
6 1.00
...
The yield is calculated for each day as Total of (GOOD+BAD) / BAD
I'm looking to use a Stored Procedure that I pass the start and end date to
it.
Whats the best way to go about get the result set back?
BartDo you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
result in yields > 1.
I think this will provide the result you requested:
create table #Judgement(JudgementDate datetime, Judgement varchar(4))
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'BAD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('04 Feb 2006', 'BAD')
go
create procedure getYield
@.start datetime,
@.end datetime
as
select JudgementDate, convert(decimal(9,2), count(*)) /
convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
end))
from #Judgement
where JudgementDate between @.start and @.end
group by JudgementDate
go
exec getYield '01 Feb 2006', '03 Feb 2006'|||You are correct, i was thinking the correct equation, but I typed the wrong
one.
Anyway, I was looking over your sugestion and I undertand now. However, if
there was
no data for a particular day, wouldn't that result in a 'Divide By Zero"
error?
Bart
"JeffB" <jeff.bolton@.citigatehudson.com> wrote in message
news:1142032601.550114.125100@.i39g2000cwa.googlegroups.com...
> Do you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
> result in yields > 1.
> I think this will provide the result you requested:
> create table #Judgement(JudgementDate datetime, Judgement varchar(4))
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'BAD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('04 Feb 2006', 'BAD')
> go
> create procedure getYield
> @.start datetime,
> @.end datetime
> as
> select JudgementDate, convert(decimal(9,2), count(*)) /
> convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
> end))
> from #Judgement
> where JudgementDate between @.start and @.end
> group by JudgementDate
> go
> exec getYield '01 Feb 2006', '03 Feb 2006'
>|||Sorry, I didn't mean when the Date was missing, I meant when the denominator
was 0.
"JeffB" <jeff.bolton@.citigatehudson.com> wrote in message
news:1142032601.550114.125100@.i39g2000cwa.googlegroups.com...
> Do you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
> result in yields > 1.
> I think this will provide the result you requested:
> create table #Judgement(JudgementDate datetime, Judgement varchar(4))
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'BAD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('04 Feb 2006', 'BAD')
> go
> create procedure getYield
> @.start datetime,
> @.end datetime
> as
> select JudgementDate, convert(decimal(9,2), count(*)) /
> convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
> end))
> from #Judgement
> where JudgementDate between @.start and @.end
> group by JudgementDate
> go
> exec getYield '01 Feb 2006', '03 Feb 2006'
>|||Using the "GOOD / (GOOD + BAD)" formula, the denominator will never be
0 because you are only looking in the Judgement table. If you were to
join to some date table in an outer join then you would do some
COALESCE on the calculations. Here is the revised format that joins to
a date table to account for missing dates:
drop table #Judgement
go
create table #Judgement(JudgementDate datetime, Judgement varchar(4))
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'BAD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('04 Feb 2006', 'BAD')
insert #Judgement values ('05 Feb 2006', 'GOOD')
go
drop table #Date
go
create table #Date([Date] datetime)
insert #Date values ('01 Feb 2006')
insert #Date values ('02 Feb 2006')
insert #Date values ('03 Feb 2006')
insert #Date values ('03 Feb 2006')
insert #Date values ('04 Feb 2006')
insert #Date values ('05 Feb 2006')
insert #Date values ('06 Feb 2006')
insert #Date values ('07 Feb 2006')
go
drop procedure getYield
go
create procedure getYield
@.start datetime,
@.end datetime
as
select JudgementDate, case when denominator = 0 then 0 else
convert(decimal(9,2), numerator) / convert(decimal(9,2), denominator)
end
from (select dt.[Date] JudgementDate, sum(case when Judgement = 'GOOD'
then 1 else 0 end) numerator, count(*) denominator
from #Date dt
left outer join #Judgement j
on dt.[Date] = j.JudgementDate
where dt.[Date] between @.start and @.end
group by dt.[Date]) x
go
exec getYield '01 Feb 2006', '07 Feb 2006'
possible judgements, GOOD and BAD.
I can filter the data to include just 1 month data, for example, Feb's data
from 02/01/06 to 02/28/06.
I would like to get output that looks like the following:
DATE YIELD
1 .90
2 .98
3 .80
4 .79
5 .60
6 1.00
...
The yield is calculated for each day as Total of (GOOD+BAD) / BAD
I'm looking to use a Stored Procedure that I pass the start and end date to
it.
Whats the best way to go about get the result set back?
BartDo you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
result in yields > 1.
I think this will provide the result you requested:
create table #Judgement(JudgementDate datetime, Judgement varchar(4))
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'BAD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('04 Feb 2006', 'BAD')
go
create procedure getYield
@.start datetime,
@.end datetime
as
select JudgementDate, convert(decimal(9,2), count(*)) /
convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
end))
from #Judgement
where JudgementDate between @.start and @.end
group by JudgementDate
go
exec getYield '01 Feb 2006', '03 Feb 2006'|||You are correct, i was thinking the correct equation, but I typed the wrong
one.
Anyway, I was looking over your sugestion and I undertand now. However, if
there was
no data for a particular day, wouldn't that result in a 'Divide By Zero"
error?
Bart
"JeffB" <jeff.bolton@.citigatehudson.com> wrote in message
news:1142032601.550114.125100@.i39g2000cwa.googlegroups.com...
> Do you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
> result in yields > 1.
> I think this will provide the result you requested:
> create table #Judgement(JudgementDate datetime, Judgement varchar(4))
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'BAD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('04 Feb 2006', 'BAD')
> go
> create procedure getYield
> @.start datetime,
> @.end datetime
> as
> select JudgementDate, convert(decimal(9,2), count(*)) /
> convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
> end))
> from #Judgement
> where JudgementDate between @.start and @.end
> group by JudgementDate
> go
> exec getYield '01 Feb 2006', '03 Feb 2006'
>|||Sorry, I didn't mean when the Date was missing, I meant when the denominator
was 0.
"JeffB" <jeff.bolton@.citigatehudson.com> wrote in message
news:1142032601.550114.125100@.i39g2000cwa.googlegroups.com...
> Do you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
> result in yields > 1.
> I think this will provide the result you requested:
> create table #Judgement(JudgementDate datetime, Judgement varchar(4))
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'BAD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('04 Feb 2006', 'BAD')
> go
> create procedure getYield
> @.start datetime,
> @.end datetime
> as
> select JudgementDate, convert(decimal(9,2), count(*)) /
> convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
> end))
> from #Judgement
> where JudgementDate between @.start and @.end
> group by JudgementDate
> go
> exec getYield '01 Feb 2006', '03 Feb 2006'
>|||Using the "GOOD / (GOOD + BAD)" formula, the denominator will never be
0 because you are only looking in the Judgement table. If you were to
join to some date table in an outer join then you would do some
COALESCE on the calculations. Here is the revised format that joins to
a date table to account for missing dates:
drop table #Judgement
go
create table #Judgement(JudgementDate datetime, Judgement varchar(4))
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'BAD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('04 Feb 2006', 'BAD')
insert #Judgement values ('05 Feb 2006', 'GOOD')
go
drop table #Date
go
create table #Date([Date] datetime)
insert #Date values ('01 Feb 2006')
insert #Date values ('02 Feb 2006')
insert #Date values ('03 Feb 2006')
insert #Date values ('03 Feb 2006')
insert #Date values ('04 Feb 2006')
insert #Date values ('05 Feb 2006')
insert #Date values ('06 Feb 2006')
insert #Date values ('07 Feb 2006')
go
drop procedure getYield
go
create procedure getYield
@.start datetime,
@.end datetime
as
select JudgementDate, case when denominator = 0 then 0 else
convert(decimal(9,2), numerator) / convert(decimal(9,2), denominator)
end
from (select dt.[Date] JudgementDate, sum(case when Judgement = 'GOOD'
then 1 else 0 end) numerator, count(*) denominator
from #Date dt
left outer join #Judgement j
on dt.[Date] = j.JudgementDate
where dt.[Date] between @.start and @.end
group by dt.[Date]) x
go
exec getYield '01 Feb 2006', '07 Feb 2006'
Subscribe to:
Posts (Atom)