Showing posts with label select. Show all posts
Showing posts with label select. Show all posts

Sunday, March 25, 2012

Analysis server cube Performance through Excel 2007

Hello Everybody

I am accessing Analysis server cube -2005 through Excel 2007 for building reports. When ever i select a row or column right click and select Filter > Hide Selected Items, it will show "running query on the OLAP server" at bottom and will not respond after that.

Ran the MDX generated by Excel 2007 directly on analysis server, even then also it takes lot of time and finally it doesnt respond. I read in the forum that the sql generated by Excel 2007 is different. how can i tweak in so that cube performance improves ?

Thanks
Kiran

Hi Kiran,

Do you have old AS 2000 to compare performance? The reason I am asking this because you can check if you have same aggregation setup in AS 2005 cube. If you don't have old cube to compare try creating aggregation on AS 2005 cube. Also you can check profiler, performance counter etc.

-Ashok

sql

Thursday, March 22, 2012

Analyser no using right index

Hi,
This Query :
SELECT 0
FROM
WOTransit -- with (index=x1,readuncommitted)
INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
WHERE WO.Cmd_No=814352
AND ISNULL(WOTransit.Charge_ref,0) <> 0
Since this morning this query is much more slow than usual
If i add : "with (index=x1,readuncommitted) ", the speed
is back to normal. because analyser usually use that
index.
If not, analyser is using a clustered index that is not
related to the query.
why doesn't he use the right index ?
What can i do to fix that ? i allready ran UPDATEUSAGE
and no change.
Thank you !
DonaldHave you rebuilt or defragged the x1 index?
--
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald|||Yes,
i dropped X1 index and recreated it
>--Original Message--
>Have you rebuilt or defragged the x1 index?
>--
>Kevin Hill
>President
>3NF Consulting
>www.3nf-inc.com/NewsGroups.htm
>www.DallasDBAs.com/forum - new DB forum for Dallas/Ft.
Worth area DBAs.
>"Donald" <anonymous@.discussions.microsoft.com> wrote in
message
>news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
>> Hi,
>> This Query :
>> SELECT 0
>> FROM
>> WOTransit -- with (index=x1,readuncommitted)
>> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
>> WHERE WO.Cmd_No=814352
>> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>>
>> Since this morning this query is much more slow than
usual
>> If i add : "with (index=x1,readuncommitted) ", the speed
>> is back to normal. because analyser usually use that
>> index.
>> If not, analyser is using a clustered index that is not
>> related to the query.
>> why doesn't he use the right index ?
>> What can i do to fix that ? i allready ran UPDATEUSAGE
>> and no change.
>> Thank you !
>> Donald
>
>.
>|||This is what I usually do. Compare the actual plan and estimated plan
(without the hint). Look for areas where the number of rows differ greatly.
Try to understand why the estimate is way-off here. You might need to
update the statistics with the FULLSCAN option in order for SQL Server to
make better estimates.
Peter Yeoh
http://www.yohz.com
Need smaller SQL2K backups? Try MiniSQLBackup
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald

Analyser no using right index

Hi,
This Query :
SELECT 0
FROM
WOTransit -- with (index=x1,readuncommitted)
INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
WHERE WO.Cmd_No=814352
AND ISNULL(WOTransit.Charge_ref,0) <> 0
Since this morning this query is much more slow than usual
If i add : "with (index=x1,readuncommitted) ", the speed
is back to normal. because analyser usually use that
index.
If not, analyser is using a clustered index that is not
related to the query.
why doesn't he use the right index ?
What can i do to fix that ? i allready ran UPDATEUSAGE
and no change.
Thank you !
DonaldHave you rebuilt or defragged the x1 index?
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx
.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald|||Yes,
i dropped X1 index and recreated it

>--Original Message--
>Have you rebuilt or defragged the x1 index?
>--
>Kevin Hill
>President
>3NF Consulting
>www.3nf-inc.com/NewsGroups.htm
>www.DallasDBAs.com/forum - new DB forum for Dallas/Ft.
Worth area DBAs.
>"Donald" <anonymous@.discussions.microsoft.com> wrote in
message
> news:1c5c901c4522c$62730400$a001280a@.phx
.gbl...
usual[vbcol=seagreen]
>
>.
>|||This is what I usually do. Compare the actual plan and estimated plan
(without the hint). Look for areas where the number of rows differ greatly.
Try to understand why the estimate is way-off here. You might need to
update the statistics with the FULLSCAN option in order for SQL Server to
make better estimates.
Peter Yeoh
http://www.yohz.com
Need smaller SQL2K backups? Try MiniSQLBackup
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx
.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald

Analyser no using right index

Hi,
This Query :
SELECT 0
FROM
WOTransit -- with (index=x1,readuncommitted)
INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
WHERE WO.Cmd_No=814352
AND ISNULL(WOTransit.Charge_ref,0) <> 0
Since this morning this query is much more slow than usual
If i add : "with (index=x1,readuncommitted) ", the speed
is back to normal. because analyser usually use that
index.
If not, analyser is using a clustered index that is not
related to the query.
why doesn't he use the right index ?
What can i do to fix that ? i allready ran UPDATEUSAGE
and no change.
Thank you !
Donald
Have you rebuilt or defragged the x1 index?
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald
|||Yes,
i dropped X1 index and recreated it

>--Original Message--
>Have you rebuilt or defragged the x1 index?
>--
>Kevin Hill
>President
>3NF Consulting
>www.3nf-inc.com/NewsGroups.htm
>www.DallasDBAs.com/forum - new DB forum for Dallas/Ft.
Worth area DBAs.
>"Donald" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
usual
>
>.
>
|||This is what I usually do. Compare the actual plan and estimated plan
(without the hint). Look for areas where the number of rows differ greatly.
Try to understand why the estimate is way-off here. You might need to
update the statistics with the FULLSCAN option in order for SQL Server to
make better estimates.
Peter Yeoh
http://www.yohz.com
Need smaller SQL2K backups? Try MiniSQLBackup
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald
sql

Tuesday, March 20, 2012

analize sp

Hi All,
I have an store procedure with a 100 and some lines, and I want to analize
the result from another sp.
How can I get the values to do a select statement?
create procedure myPro
As
select * from orders bla...
go
create procedure analizemyPro
As
declare @.temp varchar(100)
select @.temp = ordername from (here the result of myPro)
Go
Tks in advance
JFBOutput parameters,look up (stored procedures, output parameters) in BOL
or create a table and do an insert with exec
insert into table
exec myPro
http://sqlservercode.blogspot.com/|||Tks for you reply and help... We got it :)
"SQL" <denis.gobo@.gmail.com> wrote in message
news:1131643669.810105.317790@.g47g2000cwa.googlegroups.com...
> Output parameters,look up (stored procedures, output parameters) in BOL
> or create a table and do an insert with exec
> insert into table
> exec myPro
> http://sqlservercode.blogspot.com/
>

an UPDATE inside a SELECT

I was wondering if it is possible to have an UPDATE satement inside a
SELECT statment. What I want to do is select certian rows from a table
then based on the result I want to update another table. Metaphorically
something like the following
SELECT A.QTY,(UPDATE TABLE B SET QTY=A.QTY WHERE B.[ID]=A[ID]) FROM
TABLE A
*** Sent via Developersdex http://www.examnotes.net ***Hi,
Looks like you are trying to Select and Update the contents of the table in
one go.
Try to use a Stored Procedure for this purpose.
Hope this answered your Question.
thanks,
Chandra
"Hussain Al-Dhaheri" wrote:

> I was wondering if it is possible to have an UPDATE satement inside a
> SELECT statment. What I want to do is select certian rows from a table
> then based on the result I want to update another table. Metaphorically
> something like the following
> SELECT A.QTY,(UPDATE TABLE B SET QTY=A.QTY WHERE B.[ID]=A[ID]) FROM
> TABLE A
>
> *** Sent via Developersdex http://www.examnotes.net ***
>|||Hi
No, you vannot do it in that way
[Untested]
UPDATE TableA SET col=(SELECT b.col FROM TableB b WHERE b.col=col)
WHERE EXISTS (SELECT * FROM TableB b WHERE b.col=col)
SELECT <column lists> FROM
"Hussain Al-Dhaheri" <hdhaheri@.hotmail.com> wrote in message
news:e4s4e1tSFHA.3672@.TK2MSFTNGP10.phx.gbl...
> I was wondering if it is possible to have an UPDATE satement inside a
> SELECT statment. What I want to do is select certian rows from a table
> then based on the result I want to update another table. Metaphorically
> something like the following
> SELECT A.QTY,(UPDATE TABLE B SET QTY=A.QTY WHERE B.[ID]=A[ID]) FROM
> TABLE A
>
> *** Sent via Developersdex http://www.examnotes.net ***sql

Monday, March 19, 2012

An interesting Qn

Hi,
My table has the following structure
create table CompanyRights (
CompanyID int, RightID int )
Insert into CompanyRights select 1,1
Insert into CompanyRights select 1,2
Insert into CompanyRights select 1,3
Insert into CompanyRights select 2,1
Insert into CompanyRights select 2,1
and i want to choose all the companies having rights 1 and 2
select * from CompanyRights where CompanyID = 1 And RightID = 1 AND RightID
= 2
but this didn't work
Regards
LaraIs it possible without a join
With Join I have the answer
SELECT t1.CompanyID,T1.RightID
FROM CompanyRights t1
INNER join CompanyRights t2
ON t1.CompanyID =t2.CompanyID
WHERE t1.RightID = 1 AND t2.RightID = 2
regards Lara|||select * from CompanyRights where CompanyID = 1 And RightID = 1 AND RightID
= 2
The key RightID cant be 1 AND 2 at the same time, this must be
select * from CompanyRights where CompanyID = 1 And (RightID = 1 OR RightID
= 2)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Lara" <aneeshattingal@.hotpop.com> schrieb im Newsbeitrag
news:O$6pQLaSFHA.248@.TK2MSFTNGP15.phx.gbl...
> Is it possible without a join
> With Join I have the answer
> SELECT t1.CompanyID,T1.RightID
> FROM CompanyRights t1
> INNER join CompanyRights t2
> ON t1.CompanyID =t2.CompanyID
> WHERE t1.RightID = 1 AND t2.RightID = 2
> regards Lara
>
>|||Sure,
Select * From CompanyRights
Where RightID In (1,2)
-- which is same as
Select * From CompanyRights
Where RightID = 1 Or RightID = 2
"Lara" wrote:

> Is it possible without a join
> With Join I have the answer
> SELECT t1.CompanyID,T1.RightID
> FROM CompanyRights t1
> INNER join CompanyRights t2
> ON t1.CompanyID =t2.CompanyID
> WHERE t1.RightID = 1 AND t2.RightID = 2
> regards Lara
>
>|||Try,
SELECT
CompanyID
FROM
CompanyRights
WHERE
RightID = 1
or RightID = 2
group by
CompanyID
having
count(distinct RightID) = 2;
Relational Division
http://www.dbazine.com/ofinterest/o...br />
division
AMB
"Lara" wrote:

> Is it possible without a join
> With Join I have the answer
> SELECT t1.CompanyID,T1.RightID
> FROM CompanyRights t1
> INNER join CompanyRights t2
> ON t1.CompanyID =t2.CompanyID
> WHERE t1.RightID = 1 AND t2.RightID = 2
> regards Lara
>
>|||Select Distinct CompanyID
From CompanyRights R
Where Exists
(Select * From CompanyRights
Where CompanyID = R.CompanyID
And RightID = 1)
And Exists
(Select * From CompanyRights
Where CompanyID = R.CompanyID
And RightID = 2)
"Lara" wrote:

> Hi,
> My table has the following structure
> create table CompanyRights (
> CompanyID int, RightID int )
> Insert into CompanyRights select 1,1
> Insert into CompanyRights select 1,2
> Insert into CompanyRights select 1,3
> Insert into CompanyRights select 2,1
> Insert into CompanyRights select 2,1
> and i want to choose all the companies having rights 1 and 2
> select * from CompanyRights where CompanyID = 1 And RightID = 1 AND Right
ID
> = 2
> but this didn't work
> Regards
> Lara
>
>

An INSERT EXEC statement cannot be nested.


I try to select a store procedure in SqlExpress2005 which inside store procedure execute another store procedure,
When I select it but it prompt error messages "An INSERT EXEC statement cannot be nested.".
In Fire bird /Interbase store procedure we can nested. Below are the code;

declare @.dtReturnData Table(doccode nvarchar(20), docdate datetime, debtoraccount nvarchar(20))
Insert Into @.dtReturnData
Exec GetPickingList 'DO', 0, 37256, 'N', 'N', 'YES'

Select doccode, docdate, debtoraccount
From @.dtReturnData

Inside the GetPickList It will do like this, but most of the code I not included;

ALTER PROCEDURE GETPICKINGLIST
@.doctype nvarchar(2),
@.datefrom datetime,
@.dateto datetime,
@.includegrn char(1),
@.includesa char(1),
@.includedata nvarchar(5)
AS
BEGIN
declare @.dtReturnData Table(doccode nvarchar(20),
docdate datetime,
debtoraccount nvarchar(20))

IF (@.DOCTYPE = 'SI')
BEGIN
Insert Into @.dtSALESINVOICEREGISTER
Exec SALESINVOICEREGISTER @.DateFrom, @.DateTo, @.IncludeGRN, @.IncludeSA, @.IncludeData
END
ELSE
BEGIN
Insert Into @.dtDELIVERYORDERREGISTER
Exec DELIVERYORDERREGISTER @.DateFrom, @.DateTo, @.IncludeGRN, @.IncludeSA, @.IncludeData
END
Select doccode,docdate,debtoraccount From @.dtReturnData

END


So how can I select a nested store procedure? can someone help me

Jeremy,

This is a problem that comes up from time to time in SQL Server. My first suggestion when this comes up is to look at both points in which you are using the INSERT ... EXEC syntax. See if it is possible to convert at least one of the procedures into a user defined function. There is a "Plan C" for this but it is not nearly as clean as the option of converting to a function (if possible).

Also, for future keep in mind that it is a good idea to consider using functions -- especially inline functions -- instead of stored procedure when it is the intent to load the output from a procedure into a table.

See if SalesInvoiceRegister and DeliveryOrderRegister can be converted to functions.

Kent

an insert

Hello,

I need to realize an insert something like the following:

Exec GetMyID @.tName, @.MyId OUTPUT

INSERT INTO MyTable2 (MyId,MyName)

SELECT @.MyId,MyName

FROM MyTable1

Here I am getting MyID from a stored procedure and I need to insert this to MyTable2, however I need to get a new MyID for each row in MyTable1. How can I do that?

I think you will have to do a loop here and do the EXEC for each loop.|||

You could try wrapping the stored procedure in a user defined function, then referencing it in your insert. So if the function was fn_NewKey, it'd be something like

Insert into MyTable2(MyID, MyName)

select fn_NewKey() as fred, MyName

from MyTable1

Incidentall, why don't you just use an identity column for MyID? It would be a lot easier.

|||I think you will have to do a loop here and do the EXEC for each loop.|||aaaaaaaaaaaa

an In List Parameter

Is it possible (And if it is How do I do it) to create a report
parameter which allows a user to select a list of values and then
passes the entire list into the query?
IE. Parameter query returns a list of State abbreviations and the
user can then choose several which then get passed into the query as:
AND STATE IN ('GA', 'CA', 'NY')
TIA for any assistance anyone can provide me. I'm new to reporting
services and the help files haven't been all that much help.See related post:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.sqlserver.reportingsvcs&mid=aca0f4eb-9766-4437-a5f6-874f7344a827&sloc=en-us.
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Curt" <cmgaviao@.yahoo.com> wrote in message
news:582e9f38.0408190714.544de11c@.posting.google.com...
> Is it possible (And if it is How do I do it) to create a report
> parameter which allows a user to select a list of values and then
> passes the entire list into the query?
> IE. Parameter query returns a list of State abbreviations and the
> user can then choose several which then get passed into the query as:
> AND STATE IN ('GA', 'CA', 'NY')
> TIA for any assistance anyone can provide me. I'm new to reporting
> services and the help files haven't been all that much help.

Sunday, February 19, 2012

ambiguous?

ok, im trying to create this query

Code Snippet

select distinct j.eventid
from oppositeleptons j
where dbo.invmass(j.l1Ee,j.l2Ee,j.l1px,j.l2px,j.l1py,
j.l2py,j.l1pz,j.l2pz,91.1882)<10;

GO


and it throw me this error message

Msg 4121, Level 16, State 1, Procedure EvInvMass, Line 3
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.invmass", or the name is ambiguous.

the fact is.... theres no DBO column in oppositeleptons, so why this ambiguity?
the problem is that the function "dbo.invmass" does not exist

Check the owner of the function.. it needs to be called as
<owner>.invmass
where <owner> usually is dbo but it depends who created it and how.

Thursday, February 16, 2012

ambiguity performance problem

The first query execution time less than 1 second
But the second query takes around one minute

SELECT ACC_KEY1,ACC_STATUS_LAST FROM PSSIG.CLNT_ACCOUNTS INNER JOIN PSSIG.CLNT_CUSTOMERS ON
PSSIG.CLNT_ACCOUNTS.CSTMR_OID = PSSIG.CLNT_CUSTOMERS.CSTMR_OID
WHERE (PSSIG.CLNT_CUSTOMERS.CSTMR_START_DT >= '1900-1-1 12:00:00') AND
(PSSIG.CLNT_CUSTOMERS.CSTMR_END_DT <= '2106-12-31 12:00:00') AND
(PSSIG.CLNT_ACCOUNTS.ACC_KEY1 >= '0000000000000') AND
(PSSIG.CLNT_ACCOUNTS.ACC_KEY1 <= '9999999999999') AND
(PSSIG.CLNT_ACCOUNTS.ACC_STATUS_LAST in (5,-999)) AND
ACC_KEY1 > '0' ORDER BY ACC_KEY1

SELECT ACC_KEY1,ACC_STATUS_LAST FROM PSSIG.CLNT_ACCOUNTS INNER JOIN PSSIG.CLNT_CUSTOMERS ON
PSSIG.CLNT_ACCOUNTS.CSTMR_OID = PSSIG.CLNT_CUSTOMERS.CSTMR_OID
WHERE (PSSIG.CLNT_CUSTOMERS.CSTMR_START_DT >= '1900-1-1 12:00:00') AND
(PSSIG.CLNT_CUSTOMERS.CSTMR_END_DT <= '2106-12-31 12:00:00') AND
(PSSIG.CLNT_ACCOUNTS.ACC_KEY1 >= '0000000000000') AND
(PSSIG.CLNT_ACCOUNTS.ACC_KEY1 <= '9999999999999') AND
(PSSIG.CLNT_ACCOUNTS.ACC_STATUS_LAST = 5 ) AND
ACC_KEY1 > '0' ORDER BY ACC_KEY1

Note 1 : value -999 deos not exist in the table field ACC_STATUS_LAST
Note 2 : value 5 exist in most of rows about ( 999999/1000000 ) from the table rows count
Note 3 : the number of rows in each table around 15000000

Hi,

didi you have a look at the execution plan ? The execution plan can be seen in QA (using SQL 2k) or Query Pane (using SQL2k5) graphically or by using the statement SET SHOWPLAN ON before isseing the statement.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de

|||Yeah, and then post it. I would love to see how an equality query is beat out by an OR query. This looks very much like it is probably an optimizer issue, unless the plan shows something obvious...|||

thank you for this notice ,

because there is a big difference between the access plan for both queries

and I don't now why this happen ,

Monday, February 13, 2012

Am I doin this right? SELECT / ExecuteNonQuery statement

I am working on a web service method that will return weather or not a page url is stored in the database but the ExecuteNonQuery keeps returning -1. I was just wondering if i was doing anything wrong or why the ExecuteNonQuery method does not return a value of 1 or more indicating that the pageurl exists in the database? I have tried using the SQLDataReader as well to no effect and I have verified that SELECT statement refers to valid table and field names. Any help or pointers would be appreciated. I'm still kind of a newb when it comes to db programming.

1 <WebMethod()> _
2Public Function IsPageStored(ByVal pageurlAs String)As Boolean
3 If String.IsNullOrEmpty(pageurl)Then Return False
45 Dim connAs New SqlConnection()
6 conn.ConnectionString = ConfigurationManager.ConnectionStrings("dbStoredList").ConnectionString
78Dim cmdAs String9 cmd ="SELECT [" & Constants.SourceFieldName &"] "10 cmd &="FROM [" & Constants.StoredCopyTableName &"] "11 cmd &="WHERE ([" & Constants.SourceFieldName &"] ='@.Source')"12 Dim C As New SqlCommand(cmd, conn)
13 C.Parameters.AddWithValue("@.Source", New SqlTypes.SqlString(pageurl))
14 C.Parameters.Item("@.Source").CompareInfo = SqlTypes.SqlCompareOptions.IgnoreCase
1516 conn.Open()
1718Dim existsAs Boolean =False19 exists = (C.ExecuteNonQuery > 0)
2021 conn.Close()
22 C.Dispose()
23 C =Nothing24 conn.Dispose()
25 conn =Nothing
2627 Return exists
28End Function29

ExecuteNonQuery:Runs theAdomdCommand without returning any results.

For the purpose I understand, you can use ExecuteReader or ExecuteScalar if you required only one column value is return.

I think you have to use. ExecuteScalar.

Please make sure you click the Answer button if this is true answer.

Regards.

|||

In addition to what the prior person mentioned, if all you want to know is that the record exists then query for a count. SELECT COUNT(primaryKey) FROM tblName WHERE .....<add all your where conditions here>. Then you can use ExecuteScalar - much more efficient.

|||

<WebMethod()> _
2 Public Function IsPageStored(ByVal pageurlAs String)As Boolean
3 If String.IsNullOrEmpty(pageurl)Then Return False
4
5 Dim connAs New SqlConnection()
6 conn.ConnectionString = ConfigurationManager.ConnectionStrings("dbStoredList").ConnectionString
7
8 Dim cmdAs String

cmd="IF EXISTS("
9 cmd &="SELECT [" & Constants.SourceFieldName &"] "
10 cmd &="FROM [" & Constants.StoredCopyTableName &"] "
11 cmd &="WHERE ([" & Constants.SourceFieldName &"] ='@.Source')"

cmd &= ") SET @.RETVAL=1 ELSE SET @.RETVAL=0"
12 Dim C As New SqlCommand(cmd, conn)
13 C.Parameters.AddWithValue("@.Source", New SqlTypes.SqlString(pageurl))
14 C.Parameters.Item("@.Source").CompareInfo = SqlTypes.SqlCompareOptions.IgnoreCase

c.Parameters.Add("@.RETVAL", SqlDbType.Int).Direction = ParameterDirection.Output

15
16 conn.Open()
17
18 Dim existsAs Boolean =False

c.ExecuteNonQuery
19 exists = c.Parameter("@.RETVAL").Value
20
21 conn.Close()
22 C.Dispose()
23 C =Nothing
24 conn.Dispose()
25 conn =Nothing
26
27 Return exists
28 End Function

Using the EXISTS allows SQL Server to stop retrieving records when it finds the very first record that matches, instead of having to find them all. This also should force SQL Server to optimize it's query plan.

I've also changed the code from the above examples to use an output parameter instead of returning a value as a resultset. This is a more efficient way to return a simple result as well.

|||

Thanks for the tips every one, they helped me greatly!

Am I close or way off the mark?

I am trying to select rows from a SQL2000 database table and then write a random number back into each row. I have already looked into do it all in a SP but there are well documented limitations for the SQL RAND function when called in the same batch, so I need to somehow do in .Net what I already have working in classic ASP.

I can't get the UPDATE (part two section) to compile. I don't know how to call the stored procedure inside the 'foreach' loop or extract the SP parameters. I have it working in classic asp but am having a lot of trouble converting to .Net 2.0. Is the below even close to working?

// stored procedure to write externally generated random number value into database

PROCEDURE RandomizeLinks
@.L_ID int,
@.L_Rank int
AS
UPDATE Links SET L_Rank = @.L_Rank
WHERE (L_ID = @.L_ID)

// Part One select links that need random number inserted.

public DataTable GetRandLinks()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1A"].ConnectionString);
SqlCommand cmd = new SqlCommand("RandomizerSelect001", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
try
{
da.Fill(ds, "Random001");
return ds.Tables["Random001"];
}
catch
{ throw new ApplicationException("Data error"); }
}

// Part Two I need two write a random number back into each row

protected void Button1_Click(object sender, EventArgs e)
{
GetRandLinks();
int LinkID; // this generates unassigned local variable "LinkID' error
int LRank; // this generates unassigned local variable "LRank' error

SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1A"].ConnectionString);
SqlCommand cmd2 = new SqlCommand("RandomizeLinks", con2);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.AddWithValue("@.L_ID", LinkID);
cmd2.Parameters.AddWithValue("@.L_Rank", LRank);
SqlDataAdapter da2 = new SqlDataAdapter();

int RowIncrement;
RowIncrement = 0;
DataTable dt = GetRandLinks();
foreach (DataRow row in dt.Rows)
{
System.Random myRandom = new System.Random();
int LinkRank = myRandom.Next(25, 250);
LRank = LinkRank;
da2.UpdateCommand = cmd2;
RowIncrement++;
}

}

Question - instead of looping back to the database server for every row, can I pull the data into a DataTable, and then on the .Net web server update each row with it random number using system.Random and then finally read the updated DataTable back to update the SQL Database table? And if so is any of the code I have written useful to that end?

|||

Most of the T-SQL limitations can be gotten around by feeding the rand function the right 4 digits of the newid function.

|||

How would I incorporate that into this stored procedure? I am working on a SQL 2000 server, company hasn't got the money for SQL2007. And is there a way to limit the random number range to > 25 and < 250?

PROCEDURE spA_Random001
AS
DECLARE @.L_ID int
DECLARE @.L_Rank int
DECLARE cur CURSOR FOR
SELECT L_ID , L_Rank
FROM tblLinkInfo_OLD2
OPEN cur;
FETCH NEXT FROM cur
INTO @.L_ID, @.L_Rank
WHILE @.@.FETCH_STATUS = 0
BEGIN
IF (@.L_Rank > 10 AND @.L_Rank < 300)
UPDATE tblLinkInfo_OLD2 SET L_Rank = Convert(int, (L_ID)*RAND()) WHERE (L_ID = @.L_ID)
FETCH NEXT FROM cur
INTO @.L_ID, @.L_Rank
END
CLOSE cur;
DEALLOCATE cur;

|||

Thank you for the suggestion, it is an excellent solution for most applications however in my cash I need a strictly limit the random value to integers between 25 and 250. So far - pulling the table data into a DataSet, using the webserver resident System.Random to generate the random number and then writing the changes up to the SQL server seems to be the solution. I have been spoiled by the drag and drop GridViews and DataLists no I have to learn what is really going one. I am going to try to get th above solution working but I am beginning to think I am way of track.

Sunday, February 12, 2012

alternative way

SELECT *
FROM organization
WHERE (departmentID = divisionID) AND (divisionID = branchID) AND
(branchID = sectionID) AND (sectionID = unitID)

Is there anyway I can make this query more simlified w/o repeating the
same column in the where clause?

thanks
s/RC> SELECT *
> FROM organization
> WHERE (departmentID = divisionID) AND (divisionID = branchID) AND
> (branchID = sectionID) AND (sectionID = unitID)
> Is there anyway I can make this query more simlified w/o repeating the
> same column in the where clause?

SELECT *
FROM organization
WHERE departmentID = all (
select divisionID union
select branchID union
select sectionID union
select unitID
)

Craig|||"Craig Kelly" <cnkelly.nospam@.nospam.net> wrote in message
news:zsldc.35902$vo5.1148556@.bgtnsc05-news.ops.worldnet.att.net...
> > SELECT *
> > FROM organization
> > WHERE (departmentID = divisionID) AND (divisionID = branchID) AND
> > (branchID = sectionID) AND (sectionID = unitID)
> > Is there anyway I can make this query more simlified w/o repeating the
> > same column in the where clause?
> SELECT *
> FROM organization
> WHERE departmentID = all (
> select divisionID union
> select branchID union
> select sectionID union
> select unitID
> )

Keep in mind there's a very good chance the optimizer may rewrite the query
in any case.

> Craig|||I wonder it executes faster than the original query stmt?
thanks again,
s/RC

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!