Showing posts with label causing. Show all posts
Showing posts with label causing. Show all posts

Wednesday, March 28, 2012

new to mssql problem with query conversion

im managing most queries without any problems (im converting from access to mssql) but this one is causing me grief - how do i put this into mssql ?

SELECT dbo_Personal.ID, dbo_Personal.Surname1, dbo_Lead.SourceOfLead, dbo_Lead.DateOfLead, dbo_Mortgage.MortgageAppSubmitted, dbo_Mortgage.MortgageOfferedAccepted, dbo_Mortgage.MortgageDrawndown, dbo_Mortgage.MortgageApplicationClosed,
[dbo_Mortgage.MortgageCommissionAnticipated]+[dbo_Life.LifeCommissionAnticipated]+[dbo_BuildingsAndContents.BandCCommissionAnticipated]+[dbo_OtherBusiness.OtherBusinessCommissionAnticipated] AS Expr1,

[dbo_commissions.MortgageCommissionReceived]+[dbo_commissions.LifeCommissionReceived]+[dbo_commissions.BandCCommissionReceived]+[dbo_commissions.OtherBusinessCommissionReceived] AS Expr2

, IIf([Expr1]<1000,[Expr1]*0.3,IIf([Expr1]<2000,[Expr1]*0.4,[Expr1]*0.5)) AS Expr3
, IIf([Expr2]<1000,[Expr2]*0.3,IIf([Expr2]<2000,[Expr1]*0.4,[Expr2]*0.5)) AS Expr4

FROM (((((dbo_Personal INNER JOIN dbo_Lead ON dbo_Personal.ID = dbo_Lead.ID) LEFT JOIN dbo_Mortgage ON dbo_Personal.ID = dbo_Mortgage.ID) LEFT JOIN dbo_OtherBusiness ON dbo_Personal.ID = dbo_OtherBusiness.ID) LEFT JOIN dbo_BuildingsAndContents ON dbo_Personal.ID = dbo_BuildingsAndContents.ID) LEFT JOIN dbo_Commissions ON dbo_Personal.ID = dbo_Commissions.ID) LEFT JOIN dbo_Life ON dbo_Personal.ID = dbo_Life.ID
WHERE (((dbo_Lead.SourceOfLead) Like "Solutions*"));

Instead of this,
IIf([Expr1]<1000,[Expr1]*0.3,IIf([Expr1]<2000,[Expr1]*0.4,[Expr1]*0.5)) AS Expr3

Use


case
when [Expr1]<1000 then [Expr1]*0.3
when [Expr1]<2000 then [Expr1]*0.4
else [Expr1]*0.5
end as Expr3

similar syntax for Expr4 too.

Hope that helps.|||ill give it a go thanks!|||ive got as far as this :-

CREATE PROCEDURE solnorth AS

SELECT dbo.Personal.ID, dbo.Personal.Surname1, dbo.Lead.SourceOfLead, dbo.Lead.DateOfLead, dbo.Mortgage.MortgageAppSubmitted, dbo.Mortgage.MortgageOfferedAccepted, dbo.Mortgage.MortgageDrawndown, dbo.Mortgage.MortgageApplicationClosed,
dbo.Mortgage.MortgageCommissionAnticipated+dbo.Life.LifeCommissionAnticipated+dbo.BuildingsAndContents.BandCCommissionAnticipated+dbo.OtherBusiness.OtherBusinessCommissionAnticipated AS Expr1,
dbo.commissions.MortgageCommissionReceived+dbo.commissions.LifeCommissionReceived+dbo.commissions.BandCCommissionReceived+dbo.commissions.OtherBusinessCommissionReceived AS Expr2,

case
when Expr1<1000 then Expr1*0.3
when Expr1<2000 then Expr1*0.4
else Expr1*0.5
end as Expr3,

case
when Expr2<1000 then Expr2*0.3
when Expr2<2000 then Expr2*0.4
else Expr2*0.5
end as Expr4

FROM (((((dbo.Personal LEFT JOIN dbo.Lead ON dbo.Personal.ID = dbo.Lead.ID) LEFT JOIN dbo.Mortgage ON dbo.Personal.ID = dbo.Mortgage.ID) LEFT JOIN dbo.OtherBusiness ON dbo.Personal.ID = dbo.OtherBusiness.ID)
LEFT JOIN dbo.BuildingsAndContents ON dbo.Personal.ID = dbo.BuildingsAndContents.ID) LEFT JOIN dbo.Commissions ON dbo.Personal.ID = dbo.Commissions.ID)
LEFT JOIN dbo.Life ON dbo.Personal.ID = dbo.Life.ID
WHERE (((dbo.Lead.SourceOfLead) Like 'Solutions*'));
GO

but im getting invalid column name for Expr1 and Expr2 ?
where am i going wrong ?

thanks

mark|||You cannot use Expr1 and Expr2 (an alias) in the case. Just replace Expr1 and Expr2 with the same expressions you use to create Expr1 and Expr2.|||You will have to replace
Expr1
with
dbo.Mortgage.MortgageCommissionAnticipated+dbo.Life.LifeCommissionAnticipated+dbo.BuildingsAndContents.BandCCommissionAnticipated+dbo.OtherBusiness.OtherBusinessCommissionAnticipated

and

Expr2
dbo.commissions.MortgageCommissionReceived+dbo.commissions.LifeCommissionReceived+dbo.commissions.BandCCommissionReceived+dbo.commissions.OtherBusinessCommissionReceived|||great thanks that worked - well theres no errors now - just some errors with the datagrid but i should be able to sort that - thanks for the help everyone!|||quick (question how do i create Expr1 ?
eg

[dbo_Mortgage.MortgageCommissionAnticipated]+[dbo_Life.LifeCommissionAnticipated]+[dbo_BuildingsAndContents.BandCCommissionAnticipated]+[dbo_OtherBusiness.OtherBusinessCommissionAnticipated] AS Expr1

id still like to show expr1 on a datagrid if i could (eg add the columns together)

thanks

mark|||Umm, you create it by placing what you have in the select list. Am I missing something?|||heh my bad (im still learning!)
all works great now thanks for all the help

Saturday, February 25, 2012

new DM Views in 2005, which one to identify bottleneck?

Hi,
in SQL 2000 I'm using the sp_who1 storedprocedure to identify my longest
running queries and identify what is causing the delay.
sp_who1 is not a standard SP, its one found on the net which display more
info then the sp_who or sp_who2 SP.
but with 2005, what are the new options and information we can gather to
identify bottlnecks?
I want to know if my longest queries wait for the CPU, disk, network etc...
in my SQL 2000 servers, the most common waiting issue I have is the
PAGEIOLATCH wait type.
So I want to monitor my new servers and see the same queries and identify if
the same behavior appears. (and any other good information too)
any guide/recommandations?
thanks.
Jerome.Take a look at
http://www.microsoft.com/technet/pr...fprb.mspx#EYBAG
Regards
Amish Shah|||Or
The following DMV query can be used to find
which batches/requests are generating the most I/O
select top 5
(total_logical_reads/execution_count) as avg_logical_reads,
(total_logical_writes/execution_count) as avg_logical_writes,
(total_physical_reads/execution_count) as avg_phys_reads,
Execution_count,
statement_start_offset as stmt_start_offset,
sql_handle,
plan_handle
from sys.dm_exec_query_stats
order by
(total_logical_reads + total_logical_writes) Desc
--Getting text
select text
from sys.dm_exec_sql_text(
0x02000000134BE5072AFF3BDC70CF7C550689BA
DAD0E18154)
"Jeje" <willgart@.hotmail.com> wrote in message
news:OaPjQ59cGHA.2068@.TK2MSFTNGP02.phx.gbl...
> Hi,
> in SQL 2000 I'm using the sp_who1 storedprocedure to identify my longest
> running queries and identify what is causing the delay.
> sp_who1 is not a standard SP, its one found on the net which display more
> info then the sp_who or sp_who2 SP.
> but with 2005, what are the new options and information we can gather to
> identify bottlnecks?
> I want to know if my longest queries wait for the CPU, disk, network
> etc...
> in my SQL 2000 servers, the most common waiting issue I have is the
> PAGEIOLATCH wait type.
> So I want to monitor my new servers and see the same queries and identify
> if the same behavior appears. (and any other good information too)
> any guide/recommandations?
> thanks.
> Jerome.
>|||thanks.
its a good starting point.
"amish" <shahamishm@.gmail.com> wrote in message
news:1147240359.431408.226910@.e56g2000cwe.googlegroups.com...
> Take a look at
> http://www.microsoft.com/technet/pr...fprb.mspx#EYBAG
> Regards
> Amish Shah
>

new DM Views in 2005, which one to identify bottleneck?

Hi,
in SQL 2000 I'm using the sp_who1 storedprocedure to identify my longest
running queries and identify what is causing the delay.
sp_who1 is not a standard SP, its one found on the net which display more
info then the sp_who or sp_who2 SP.
but with 2005, what are the new options and information we can gather to
identify bottlnecks?
I want to know if my longest queries wait for the CPU, disk, network etc...
in my SQL 2000 servers, the most common waiting issue I have is the
PAGEIOLATCH wait type.
So I want to monitor my new servers and see the same queries and identify if
the same behavior appears. (and any other good information too)
any guide/recommandations?
thanks.
Jerome.Take a look at
http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx#EYBAG
Regards
Amish Shah|||Or
The following DMV query can be used to find
which batches/requests are generating the most I/O
select top 5
(total_logical_reads/execution_count) as avg_logical_reads,
(total_logical_writes/execution_count) as avg_logical_writes,
(total_physical_reads/execution_count) as avg_phys_reads,
Execution_count,
statement_start_offset as stmt_start_offset,
sql_handle,
plan_handle
from sys.dm_exec_query_stats
order by
(total_logical_reads + total_logical_writes) Desc
--Getting text
select text
from sys.dm_exec_sql_text(
0x02000000134BE5072AFF3BDC70CF7C550689BADAD0E18154)
"Jeje" <willgart@.hotmail.com> wrote in message
news:OaPjQ59cGHA.2068@.TK2MSFTNGP02.phx.gbl...
> Hi,
> in SQL 2000 I'm using the sp_who1 storedprocedure to identify my longest
> running queries and identify what is causing the delay.
> sp_who1 is not a standard SP, its one found on the net which display more
> info then the sp_who or sp_who2 SP.
> but with 2005, what are the new options and information we can gather to
> identify bottlnecks?
> I want to know if my longest queries wait for the CPU, disk, network
> etc...
> in my SQL 2000 servers, the most common waiting issue I have is the
> PAGEIOLATCH wait type.
> So I want to monitor my new servers and see the same queries and identify
> if the same behavior appears. (and any other good information too)
> any guide/recommandations?
> thanks.
> Jerome.
>|||thanks.
its a good starting point.
"amish" <shahamishm@.gmail.com> wrote in message
news:1147240359.431408.226910@.e56g2000cwe.googlegroups.com...
> Take a look at
> http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx#EYBAG
> Regards
> Amish Shah
>