Hi there,
I hoping someone can help me reduce the number of line of code I'm
using, as these IF's are nested inside a bigger one.
The main problem I have is I need to add another variable to the IF and
don't want to copy and paste and make this statement even larger.
I have tried playing about with EXEC but with no joy. As far as I'm
aware it's not possible to do @.CSOrder > 0 ? CSPerson = @.CSOrder :
CSPerson > 0
I'm using SQL Server 2000 SP4.
Hopefully I'm missing the obvious, although any help or suggestions are
welcome.
-- snippet --
IF @.CSOrder > 0 AND @.SalesOrder > 0
SELECT * FROM MainOrder
LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
WHERE JobFlow.Component=6
AND (Status = @.InProgress
OR Status = @.Complete
OR Status = @.Cancelled
OR Status = @.Acknowledged)
AND CSPerson = @.CSOrder
AND SalesPerson = @.SalesOrder
ORDER BY DateToArrive, Status
ELSE IF @.CSOrder > 0
SELECT * FROM MainOrder
LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
WHERE JobFlow.Component=6
AND (Status = @.InProgress
OR Status = @.Complete
OR Status = @.Cancelled
OR Status = @.Acknowledged)
AND CSPerson = @.CSOrder
ORDER BY DateToArrive, Status
ELSE IF @.SalesOrder > 0
SELECT * FROM MainOrder
LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
WHERE JobFlow.Component=6
AND (Status = @.InProgress
OR Status = @.Complete
OR Status = @.Cancelled
OR Status = @.Acknowledged)
AND SalesPerson = @.SalesOrder
ORDER BY DateToArrive, Status
ELSE
SELECT * FROM MainOrder
LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
WHERE JobFlow.Component=6
AND (Status = @.InProgress
OR Status = @.Complete
OR Status = @.Cancelled
OR Status = @.Acknowledged)
ORDER BY DateToArrive, StatusWhat you can do is something like this.
SELECT * FROM MainOrder
LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
WHERE JobFlow.Component=6
AND (Status = @.InProgress
OR Status = @.Complete
OR Status = @.Cancelled
OR Status = @.Acknowledged)
AND CSPerson = CSAE @.CSOrder WHEN 0 THEN CSPerson ELSE @.CSOrder
END
AND SalesPerson = CASE @.SalesOrder WHEN 0 THEN SalesPerson ELSE
@.SalesOrder END
AND ... -- add more
AND SalesPerson = @.SalesOrder
ORDER BY DateToArrive, Status|||Mia,
Try something like this
DECLARE @.strWHERE varchar(200)
SET @.strWHERE = ''
IF @.CSOrder > 0 AND @.SalesOrder > 0 THEN @.strWHERE = 'AND CSPerson =
@.CSOrder AND SalesPerson = @.SalesOrder'
IF @.CSOrder > 0 AND @.SalesOrder <> 0 THEN @.strWHERE = 'AND CSPerson =
@.CSOrder'
IF @.CSOrder <> 0 AND @.SalesOrder > 0 THEN @.strWHERE = 'AND SalesPerson =
@.SalesOrder'
DECLARE @.sSQL varchar(2000)
SET @.sSQL = ''
SET @.sSQL = @.sSQL + ' SELECT * FROM MainOrder '
SET @.sSQL = @.sSQL + ' LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id] '
SET @.sSQL = @.sSQL + ' LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id] '
SET @.sSQL = @.sSQL + ' WHERE JobFlow.Component=6 '
SET @.sSQL = @.sSQL + ' AND (Status = @.InProgress '
SET @.sSQL = @.sSQL + ' OR Status = @.Complete '
SET @.sSQL = @.sSQL + ' OR Status = @.Cancelled '
SET @.sSQL = @.sSQL + ' OR Status = @.Acknowledged) '
SET @.sSQL = @.sSQL + @.strWHERE
SET @.sSQL = @.sSQL + ' AND SalesPerson = @.SalesOrder '
SET @.sSQL = @.sSQL + ' AORDER BY DateToArrive, Status '
EXEC (@.sSQL)
Hope this assists,
Tony
"mia_cid@.hotmail.com" wrote:
> Hi there,
> I hoping someone can help me reduce the number of line of code I'm
> using, as these IF's are nested inside a bigger one.
> The main problem I have is I need to add another variable to the IF and
> don't want to copy and paste and make this statement even larger.
> I have tried playing about with EXEC but with no joy. As far as I'm
> aware it's not possible to do @.CSOrder > 0 ? CSPerson = @.CSOrder :
> CSPerson > 0
> I'm using SQL Server 2000 SP4.
> Hopefully I'm missing the obvious, although any help or suggestions are
> welcome.
> -- snippet --
> IF @.CSOrder > 0 AND @.SalesOrder > 0
> SELECT * FROM MainOrder
> LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
> LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
> WHERE JobFlow.Component=6
> AND (Status = @.InProgress
> OR Status = @.Complete
> OR Status = @.Cancelled
> OR Status = @.Acknowledged)
> AND CSPerson = @.CSOrder
> AND SalesPerson = @.SalesOrder
> ORDER BY DateToArrive, Status
> ELSE IF @.CSOrder > 0
> SELECT * FROM MainOrder
> LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
> LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
> WHERE JobFlow.Component=6
> AND (Status = @.InProgress
> OR Status = @.Complete
> OR Status = @.Cancelled
> OR Status = @.Acknowledged)
> AND CSPerson = @.CSOrder
> ORDER BY DateToArrive, Status
> ELSE IF @.SalesOrder > 0
> SELECT * FROM MainOrder
> LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
> LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
> WHERE JobFlow.Component=6
> AND (Status = @.InProgress
> OR Status = @.Complete
> OR Status = @.Cancelled
> OR Status = @.Acknowledged)
> AND SalesPerson = @.SalesOrder
> ORDER BY DateToArrive, Status
> ELSE
> SELECT * FROM MainOrder
> LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id]
> LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id]
> WHERE JobFlow.Component=6
> AND (Status = @.InProgress
> OR Status = @.Complete
> OR Status = @.Cancelled
> OR Status = @.Acknowledged)
> ORDER BY DateToArrive, Status
>|||Ooops,
take the following line out of the code:::
SET @.sSQL = @.sSQL + ' AND SalesPerson = @.SalesOrder '
it was an oversight on my part, sorry,
Tony
"Tony Scott" wrote:
> Mia,
> Try something like this
>
> DECLARE @.strWHERE varchar(200)
> SET @.strWHERE = ''
> IF @.CSOrder > 0 AND @.SalesOrder > 0 THEN @.strWHERE = 'AND CSPerson =
> @.CSOrder AND SalesPerson = @.SalesOrder'
> IF @.CSOrder > 0 AND @.SalesOrder <> 0 THEN @.strWHERE = 'AND CSPerson =
> @.CSOrder'
> IF @.CSOrder <> 0 AND @.SalesOrder > 0 THEN @.strWHERE = 'AND SalesPerson =
> @.SalesOrder'
> DECLARE @.sSQL varchar(2000)
> SET @.sSQL = ''
> SET @.sSQL = @.sSQL + ' SELECT * FROM MainOrder '
> SET @.sSQL = @.sSQL + ' LEFT JOIN AnCJobs ON MainOrder.[id] = AnCJobs.[id] '
> SET @.sSQL = @.sSQL + ' LEFT JOIN JobFlow ON JobFlow.[id] = MainOrder.[id] '
> SET @.sSQL = @.sSQL + ' WHERE JobFlow.Component=6 '
> SET @.sSQL = @.sSQL + ' AND (Status = @.InProgress '
> SET @.sSQL = @.sSQL + ' OR Status = @.Complete '
> SET @.sSQL = @.sSQL + ' OR Status = @.Cancelled '
> SET @.sSQL = @.sSQL + ' OR Status = @.Acknowledged) '
> SET @.sSQL = @.sSQL + @.strWHERE
> SET @.sSQL = @.sSQL + ' AND SalesPerson = @.SalesOrder '
> SET @.sSQL = @.sSQL + ' AORDER BY DateToArrive, Status '
> EXEC (@.sSQL)
>
> Hope this assists,
> Tony
> "mia_cid@.hotmail.com" wrote:
>|||Thanks for the help guys,
Patrik I liked your idea, only I need:
AND CSPerson = CASE @.CSOrder WHEN > 0 THEN CSPerson ELSE @.CSOrder
Not
AND CSPerson = CASE @.CSOrder WHEN 0 THEN CSPerson ELSE @.CSOrder
Or
AND CSPerson >= CASE @.CSOrder WHEN 0 THEN CSPerson ELSE @.CSOrder
As if @.CSOrder = 0, then I want to select everything, so CSPerson needs
to be greater than 0.
Tony,
I had a couple of errors with your original code, so now have:
DECLARE @.strWHERE varchar(200)
SET @.strWHERE = ''
IF @.CSOrder > 0 AND @.SalesOrder > 0
SET @.strWHERE = 'AND CSPerson = @.CSOrder AND SalesPerson =
@.SalesOrder'
IF @.CSOrder > 0 AND @.SalesOrder <> 0
SET @.strWHERE = 'AND CSPerson = @.CSOrder'
IF @.CSOrder <> 0 AND @.SalesOrder > 0
SET @.strWHERE = 'AND SalesPerson = @.SalesOrder'
DECLARE @.sSQL varchar(2000)
SET @.sSQL = ''
SET @.sSQL = @.sSQL + ' SELECT * FROM MainOrder '
SET @.sSQL = @.sSQL + ' LEFT JOIN AnCJobs ON MainOrder.[id] =
AnCJobs.[id] '
SET @.sSQL = @.sSQL + ' LEFT JOIN JobFlow ON JobFlow.[id] =
MainOrder.[id] '
SET @.sSQL = @.sSQL + ' WHERE JobFlow.Component=6 '
SET @.sSQL = @.sSQL + ' AND (Status = @.InProgress '
SET @.sSQL = @.sSQL + ' OR Status = @.Complete '
SET @.sSQL = @.sSQL + ' OR Status = @.Cancelled '
SET @.sSQL = @.sSQL + ' OR Status = @.Acknowledged) '
SET @.sSQL = @.sSQL + @.strWHERE
SET @.sSQL = @.sSQL + ' ORDER BY DateToArrive, Status'
EXEC (@.sSQL)
Only I've getting a syntax error near the keyword 'ELSE'. If I comment
this code out and put a standard SELECT in it works okay.
Any ideas?|||You can do that.
AND CSPerson = CASE WHEN @.CSOrder > 0 THEN CSPerson ELSE @.CSOrder END
Although, it would probably be more efficient with dynamic sql in this
case.
I suggest that you use sp_executesql instaead of exec.
Read sommarskogs really good article about using dynamic sql.
http://www.sommarskog.se/dynamic_sql.html|||Thanks for that Partrik,
I just needed it the other way round:
AND CSPerson = CASE WHEN @.CSOrder > 0 THEN @.CSOrder ELSE CSPerson END
It works a treat, for the time being I'm going to stick with it as
it'll be running over a LAN, have bookmarked the site you recommended
and will have a read when I get the chance.
Thanks again to Tony for his help as well.
Showing posts with label reduce. Show all posts
Showing posts with label reduce. Show all posts
Tuesday, March 20, 2012
Wednesday, March 7, 2012
Can SQL Reporting Services be installed on a virtual PC
Just thinking of ways to reduce server footprint in our Data Center. Is this
possible?
Thanks
--
Jeff Bennett
SQL DBA
St. Louis, MOYes, it's possible.
You'll need to tune it, and it probably won't be too happy if you run lots
of disk intensive reports on it, but it will work. I ran a virtual pc with
Reporting Services 2000 and Analysis Services 2000 as a development server
for almost a year. You'll need to give it lots of RAM, as you can't really
use a pagefile, but other than that it behaves more or less like a normal
server.
Kaisa M. Lindahl Lervik
"Chudman" <Chudman@.discussions.microsoft.com> wrote in message
news:89967826-0F61-46FB-B330-709E33850A9F@.microsoft.com...
> Just thinking of ways to reduce server footprint in our Data Center. Is
> this
> possible?
> Thanks
> --
> Jeff Bennett
> SQL DBA
> St. Louis, MO|||I've run into the similar problem with Virtual PC. Reporting services
appears to operate correctly under the data and layout tab but when I select
Preview it errors out saying an unexpected error occurs. These same reports
work fine on my physical machine using the same verion of reporting services
& Windows XP. I've dedicated 1024 MB of Ram to my virtual which I would
think would be enough memory. Any suggestions on how I can fix reports
services so that I can view the preview of my reports?
Craig
"Kaisa M. Lindahl Lervik" wrote:
> Yes, it's possible.
> You'll need to tune it, and it probably won't be too happy if you run lots
> of disk intensive reports on it, but it will work. I ran a virtual pc with
> Reporting Services 2000 and Analysis Services 2000 as a development server
> for almost a year. You'll need to give it lots of RAM, as you can't really
> use a pagefile, but other than that it behaves more or less like a normal
> server.
> Kaisa M. Lindahl Lervik
>
> "Chudman" <Chudman@.discussions.microsoft.com> wrote in message
> news:89967826-0F61-46FB-B330-709E33850A9F@.microsoft.com...
> > Just thinking of ways to reduce server footprint in our Data Center. Is
> > this
> > possible?
> >
> > Thanks
> > --
> > Jeff Bennett
> > SQL DBA
> > St. Louis, MO
>|||Are you running a Reporting Services server on your virtual PC? Or just the
client tools.
I was a bit superficial in my first reply.
I'm using Virtual Server 2005 R2 (beta) on my Vista PC. I have one image
with Windows XP and the Reporting Services 2000 client tools running on my
Vista PC, and I use this daily to develop reports. I don't have SQL Server,
Analysis Services or Reporting Services SERVER applications on this, I get
my data from other servers, and I deploy to another server running RS 2000.
I don't have any problems using Preview on this, except on very heavy
reports (30 pages with lots of calculations). My virtual image has 1024 MB,
leaving 1024 MB for my host pc.
I also ran a virtual machine on Virtual Server 2005 on a host server. It was
a Windows Server 2003 Std. edition with SQL Server, Analysis Services and
Reporting Services 2000. I gave it 3 GB RAM, which made it happy. I didn't
do any development work on this one though, just used it to run the reports
and OLAP cubes.
Maybe using Virutal Server 2005 gives it better performance than Virtual PC.
Which edition of Virtual PC are you using? 2004 or 2007?
With regards,
Kaisa M. Lindahl Lervik
"Craig Schneider" <Craig Schneider@.discussions.microsoft.com> wrote in
message news:1A6EAE2D-7752-446E-9FF7-2BFBA83E8DAB@.microsoft.com...
> I've run into the similar problem with Virtual PC. Reporting services
> appears to operate correctly under the data and layout tab but when I
> select
> Preview it errors out saying an unexpected error occurs. These same
> reports
> work fine on my physical machine using the same verion of reporting
> services
> & Windows XP. I've dedicated 1024 MB of Ram to my virtual which I would
> think would be enough memory. Any suggestions on how I can fix reports
> services so that I can view the preview of my reports?
> Craig
> "Kaisa M. Lindahl Lervik" wrote:
>> Yes, it's possible.
>> You'll need to tune it, and it probably won't be too happy if you run
>> lots
>> of disk intensive reports on it, but it will work. I ran a virtual pc
>> with
>> Reporting Services 2000 and Analysis Services 2000 as a development
>> server
>> for almost a year. You'll need to give it lots of RAM, as you can't
>> really
>> use a pagefile, but other than that it behaves more or less like a normal
>> server.
>> Kaisa M. Lindahl Lervik
>>
>> "Chudman" <Chudman@.discussions.microsoft.com> wrote in message
>> news:89967826-0F61-46FB-B330-709E33850A9F@.microsoft.com...
>> > Just thinking of ways to reduce server footprint in our Data Center.
>> > Is
>> > this
>> > possible?
>> >
>> > Thanks
>> > --
>> > Jeff Bennett
>> > SQL DBA
>> > St. Louis, MO
>>
possible?
Thanks
--
Jeff Bennett
SQL DBA
St. Louis, MOYes, it's possible.
You'll need to tune it, and it probably won't be too happy if you run lots
of disk intensive reports on it, but it will work. I ran a virtual pc with
Reporting Services 2000 and Analysis Services 2000 as a development server
for almost a year. You'll need to give it lots of RAM, as you can't really
use a pagefile, but other than that it behaves more or less like a normal
server.
Kaisa M. Lindahl Lervik
"Chudman" <Chudman@.discussions.microsoft.com> wrote in message
news:89967826-0F61-46FB-B330-709E33850A9F@.microsoft.com...
> Just thinking of ways to reduce server footprint in our Data Center. Is
> this
> possible?
> Thanks
> --
> Jeff Bennett
> SQL DBA
> St. Louis, MO|||I've run into the similar problem with Virtual PC. Reporting services
appears to operate correctly under the data and layout tab but when I select
Preview it errors out saying an unexpected error occurs. These same reports
work fine on my physical machine using the same verion of reporting services
& Windows XP. I've dedicated 1024 MB of Ram to my virtual which I would
think would be enough memory. Any suggestions on how I can fix reports
services so that I can view the preview of my reports?
Craig
"Kaisa M. Lindahl Lervik" wrote:
> Yes, it's possible.
> You'll need to tune it, and it probably won't be too happy if you run lots
> of disk intensive reports on it, but it will work. I ran a virtual pc with
> Reporting Services 2000 and Analysis Services 2000 as a development server
> for almost a year. You'll need to give it lots of RAM, as you can't really
> use a pagefile, but other than that it behaves more or less like a normal
> server.
> Kaisa M. Lindahl Lervik
>
> "Chudman" <Chudman@.discussions.microsoft.com> wrote in message
> news:89967826-0F61-46FB-B330-709E33850A9F@.microsoft.com...
> > Just thinking of ways to reduce server footprint in our Data Center. Is
> > this
> > possible?
> >
> > Thanks
> > --
> > Jeff Bennett
> > SQL DBA
> > St. Louis, MO
>|||Are you running a Reporting Services server on your virtual PC? Or just the
client tools.
I was a bit superficial in my first reply.
I'm using Virtual Server 2005 R2 (beta) on my Vista PC. I have one image
with Windows XP and the Reporting Services 2000 client tools running on my
Vista PC, and I use this daily to develop reports. I don't have SQL Server,
Analysis Services or Reporting Services SERVER applications on this, I get
my data from other servers, and I deploy to another server running RS 2000.
I don't have any problems using Preview on this, except on very heavy
reports (30 pages with lots of calculations). My virtual image has 1024 MB,
leaving 1024 MB for my host pc.
I also ran a virtual machine on Virtual Server 2005 on a host server. It was
a Windows Server 2003 Std. edition with SQL Server, Analysis Services and
Reporting Services 2000. I gave it 3 GB RAM, which made it happy. I didn't
do any development work on this one though, just used it to run the reports
and OLAP cubes.
Maybe using Virutal Server 2005 gives it better performance than Virtual PC.
Which edition of Virtual PC are you using? 2004 or 2007?
With regards,
Kaisa M. Lindahl Lervik
"Craig Schneider" <Craig Schneider@.discussions.microsoft.com> wrote in
message news:1A6EAE2D-7752-446E-9FF7-2BFBA83E8DAB@.microsoft.com...
> I've run into the similar problem with Virtual PC. Reporting services
> appears to operate correctly under the data and layout tab but when I
> select
> Preview it errors out saying an unexpected error occurs. These same
> reports
> work fine on my physical machine using the same verion of reporting
> services
> & Windows XP. I've dedicated 1024 MB of Ram to my virtual which I would
> think would be enough memory. Any suggestions on how I can fix reports
> services so that I can view the preview of my reports?
> Craig
> "Kaisa M. Lindahl Lervik" wrote:
>> Yes, it's possible.
>> You'll need to tune it, and it probably won't be too happy if you run
>> lots
>> of disk intensive reports on it, but it will work. I ran a virtual pc
>> with
>> Reporting Services 2000 and Analysis Services 2000 as a development
>> server
>> for almost a year. You'll need to give it lots of RAM, as you can't
>> really
>> use a pagefile, but other than that it behaves more or less like a normal
>> server.
>> Kaisa M. Lindahl Lervik
>>
>> "Chudman" <Chudman@.discussions.microsoft.com> wrote in message
>> news:89967826-0F61-46FB-B330-709E33850A9F@.microsoft.com...
>> > Just thinking of ways to reduce server footprint in our Data Center.
>> > Is
>> > this
>> > possible?
>> >
>> > Thanks
>> > --
>> > Jeff Bennett
>> > SQL DBA
>> > St. Louis, MO
>>
Subscribe to:
Posts (Atom)