Showing posts with label wrong. Show all posts
Showing posts with label wrong. Show all posts

Tuesday, March 27, 2012

Cursor inside a cursor

I'm new to cursors, and I'm not sure what's wrong with this code, it run for ever and when I stop it I get cursor open errors

declare Q cursor for
select systudentid from satrans

declare @.id int

open Q
fetch next from Q into @.id
while @.@.fetch_status = 0
begin

declare c cursor for

Select
b.ssn,
SaTrans.SyStudentID,
satrans.date,
satrans.type,
SaTrans.SyCampusID,
Amount = Case SaTrans.Type
When 'P' Then SaTrans.Amount * -1
When 'C' Then SaTrans.Amount * -1
Else SaTrans.Amount END

From SaTrans , systudent b where satrans.systudentid = b.systudentid

and satrans.systudentid = @.id

declare @.arbalance money, @.type varchar, @.ssn varchar, @.amount money, @.systudentid int, @.transdate datetime, @.sycampusid int, @.before money

set @.arbalance = 0
open c
fetch next from c into @.ssn, @.systudentid, @.transdate, @.type, @.sycampusid, @.amount

while @.@.fetch_status = 0
begin

set @.arbalance = @.arbalance + @.amount
set @.before = @.arbalance -@.amount

insert c2000_utility1..tempbalhistory1
select @.systudentid systudentid, @.sycampusid sycampusid, @.transdate transdate, @.amount amount, @.type type, @.arbalance Arbalance, @.before BeforeBalance
where( convert (int,@.amount) <= -50
or @.amount * -1 > @.before * .02)
and @.type = 'P'

fetch next from c into @.ssn, @.systudentid, @.transdate, @.type, @.sycampusid, @.amount
end
close c
deallocate c
fetch next from Q into @.id

end
close Q
deallocate Q

select * from c2000_utility1..tempbalhistory1
truncate table c2000_utility1..tempbalhistory1Did you write this? Or was it given to you?

You don't need a cursor at all for this (although I'm having trouble trying to figure out what you're trying to do)...

Lose Cursor 1 altogethr.

Use the SELECT (which already has the table in it you want) as the Portion of the INSERT Statement...that's it...

Except for this

where( convert (int,@.amount) <= -50
or @.amount * -1 > @.before * .02)
and @.type = 'P'

Which I have no idea what you want.

I expect all you need to do is add that to the select

Thursday, March 22, 2012

cursor

What' s wrong with this code?
Declare @.UDName varchar(150)
Declare @.UName varchar(50)
Declare @.Domain varchar(50)
Declare @.EMail varchar(20)
Declare @.GName varchar(50)
Declare @.Description varchar(150)
Declare @.FName varchar(50)
Declare @.ShortName varchar(150)
Declare UserCursor Cursor
For
SELECT ( UsrUsers.[Domain] + '' + UsrUsers.UserName) AS
UDName, UsrUsers.UserName as UName, UsrUsers.[Domain],UsrUsers.EMail,
UsrGroups.Name AS GName, UsrGroups.Description,
UsrFunctions.Name AS FName, UsrFunctions.ShortName AS
ShortName
FROM UsrUsers INNER JOIN
UsrUsersGroups ON UsrUsers.UserID =
UsrUsersGroups.UserID INNER JOIN
UsrFunctions INNER JOIN
UsrFunctionsGroups ON UsrFunctions.FunctionID =
UsrFunctionsGroups.FunctionID INNER JOIN
UsrGroups ON UsrFunctionsGroups.GroupID =
UsrGroups.GroupID ON UsrUsersGroups.GroupID = UsrGroups.GroupID
ORDER BY UName,GName,FName
open UserCursor
fetch next from UserCursor
into
@.UDName,@.UName,@.Domain,@.EMail,@.GName,@.De
scription,@.FName,@.ShortName
while @.@.fetch_status = 0
begin
select
@.UDName,@.UName,@.Domain,@.EMail,@.GName,@.De
scription,@.FName,@.ShortName
end
close UserCursor
deallocate UserCursor
I run it in sql query analizer and it goes on and on until 'Not Responding'
HrckoTechnically, you need a FETCH inside the loop, else you are working on the s
ame row endlessly. But
the cursor seems totally meaningless to me. Why not just have the SELETE sta
tement as is? What is
the purpose of using a cursor here? Why do you want to return one table for
each row, each table
containing one row?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Hrvoje Voda" <hrvoje.voda@.luatech.com> wrote in message news:djl4p1$omg$1@.ss405.t-com.hr..
.
> What' s wrong with this code?
> Declare @.UDName varchar(150)
> Declare @.UName varchar(50)
> Declare @.Domain varchar(50)
> Declare @.EMail varchar(20)
> Declare @.GName varchar(50)
> Declare @.Description varchar(150)
> Declare @.FName varchar(50)
> Declare @.ShortName varchar(150)
> Declare UserCursor Cursor
> For
> SELECT ( UsrUsers.[Domain] + '' + UsrUsers.UserName) AS UDName, UsrU
sers.UserName as
> UName, UsrUsers.[Domain],UsrUsers.EMail, UsrGroups.Name AS GName, UsrGroups.Descri
ption,
> UsrFunctions.Name AS FName, UsrFunctions.ShortName AS
ShortName
> FROM UsrUsers INNER JOIN
> UsrUsersGroups ON UsrUsers.UserID = UsrUsersGroups.Us
erID INNER JOIN
> UsrFunctions INNER JOIN
> UsrFunctionsGroups ON UsrFunctions.FunctionID = UsrFu
nctionsGroups.FunctionID
> INNER JOIN
> UsrGroups ON UsrFunctionsGroups.GroupID = UsrGroups.G
roupID ON
> UsrUsersGroups.GroupID = UsrGroups.GroupID
> ORDER BY UName,GName,FName
> open UserCursor
> fetch next from UserCursor
> into
> @.UDName,@.UName,@.Domain,@.EMail,@.GName,@.De
scription,@.FName,@.ShortName
> while @.@.fetch_status = 0
> begin
> select @.UDName,@.UName,@.Domain,@.EMail,@.GName,@.De
scription,@.FName,@.Shor
tName
> end
> close UserCursor
> deallocate UserCursor
> I run it in sql query analizer and it goes on and on until 'Not Responding
'
> Hrcko
>|||I have to read all the users from the table first and then functions.
I need it for report.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uLX0HiV2FHA.1184@.TK2MSFTNGP12.phx.gbl...
> Technically, you need a FETCH inside the loop, else you are working on the
> same row endlessly. But the cursor seems totally meaningless to me. Why
> not just have the SELETE statement as is? What is the purpose of using a
> cursor here? Why do you want to return one table for each row, each table
> containing one row?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Hrvoje Voda" <hrvoje.voda@.luatech.com> wrote in message
> news:djl4p1$omg$1@.ss405.t-com.hr...
>|||>I have to read all the users from the table first and then functions.
I'm afraid that I don't understand what you mean by "and then function"...
Just be aware that using a cursor is often *much* slower, and often you have
to write more code
which is harder to maintain, compared to a single SELECT statement.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Hrvoje Voda" <hrvoje.voda@.luatech.com> wrote in message news:djl5p1$qnf$1@.ss405.t-com.hr..
.
>I have to read all the users from the table first and then functions.
> I need it for report.
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:uLX0HiV2FHA.1184@.TK2MSFTNGP12.phx.gbl...
>|||I have to tables: Users and Functions.
In my report(crystal report 11) i have to read all data from table Users and
then all data from table Functions, because in Detail section it reads
record by record - so I get a line with user name and then a line with
function name. I don't want that.
I want all users and then all functions.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OcMatwV2FHA.1188@.TK2MSFTNGP12.phx.gbl...
> I'm afraid that I don't understand what you mean by "and then
> function"...
> Just be aware that using a cursor is often *much* slower, and often you
> have to write more code which is harder to maintain, compared to a single
> SELECT statement.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Hrvoje Voda" <hrvoje.voda@.luatech.com> wrote in message
> news:djl5p1$qnf$1@.ss405.t-com.hr...
>|||As Tibor indicated, you'll probably be better off not using a cursor.
To help you with that, please post DDL, sample data and show your
required results. See:
http://www.aspfaq.com/etiquette.asp?id=5006
David Portas
SQL Server MVP
--|||Those are two tables, which translates to two resultsets, which in turn give
s
you a typical master/detail dataset to work with. What's wrong with that?
ML

Tuesday, March 20, 2012

Current log - too much entries?

Hello,

does anyone know what could be wrong? There's a lot of similar entries
in the SQL Server current log:

2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'
2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'
2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'

There are hundreds of similar entries that repeat every few seconds. The
database works quite slowly and the users get 'Connection timeout'
message very often.

Thanks for any advice.

...:: fabio"Fabio" <fabio@.anti-spam.inet.alpha.pl> wrote in message
news:bumbod$d6c$1@.nemesis.news.tpi.pl...
> Hello,
> does anyone know what could be wrong? There's a lot of similar entries
> in the SQL Server current log:
> 2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'
> There are hundreds of similar entries that repeat every few seconds. The
> database works quite slowly and the users get 'Connection timeout'
> message very often.
> Thanks for any advice.
> ..:: fabio

Probably the database is set to autoclose - if there are no active
connections, then it is closed. That means when a connection is made, the
database is opened again, which takes time. You can check like this:

select databasepropertyex('DB_NAME', 'IsAutoClose')

1 means it's on, so you can turn it off like this:

alter database DB_NAME set auto_close off

Simon

Current Log - Too Much Entries

Hello,
does anyone know what could be wrong? There's a lot of similar entries
in the SQL Server current log:
2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'
2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'
2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'
There are hundreds of similar entries that repeat every few seconds. The
database works quite slowly and the users get 'Connection timeout'
message very often.
Thanks for any advice.
..:: fabioCheck if the database option "Autoclose" is turned on and turn it off.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Fabio" <fabio@.anti-spam.inet.alpha.pl> wrote in message
news:bumc1f$2hu$1@.atlantis.news.tpi.pl...
quote:

> Hello,
> does anyone know what could be wrong? There's a lot of similar entries
> in the SQL Server current log:
> 2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'
> There are hundreds of similar entries that repeat every few seconds. The
> database works quite slowly and the users get 'Connection timeout'
> message very often.
> Thanks for any advice.
> ..:: fabio
>
|||Uncheck 'AUTO CLOSE' on the database properties options page. (Right click
database name in Enterprise Mangler, select Properties, click on Options
tab.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
"Fabio" <fabio@.anti-spam.inet.alpha.pl> wrote in message
news:bumc1f$2hu$1@.atlantis.news.tpi.pl...
quote:

> Hello,
> does anyone know what could be wrong? There's a lot of similar entries
> in the SQL Server current log:
> 2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'
> There are hundreds of similar entries that repeat every few seconds. The
> database works quite slowly and the users get 'Connection timeout'
> message very often.
> Thanks for any advice.
> ..:: fabio
>
|||Fabio wrote:
Thanks a lot, Dejan and Geoff.
After turning the 'auto close' option the database works much faster and
the messages about database starting don't appear in the error log.
..:: fabio

Current Log - Too Much Entries

Hello,
does anyone know what could be wrong? There's a lot of similar entries
in the SQL Server current log:
2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'
2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'
2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'
There are hundreds of similar entries that repeat every few seconds. The
database works quite slowly and the users get 'Connection timeout'
message very often.
Thanks for any advice.
..:: fabioCheck if the database option "Autoclose" is turned on and turn it off.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Fabio" <fabio@.anti-spam.inet.alpha.pl> wrote in message
news:bumc1f$2hu$1@.atlantis.news.tpi.pl...
> Hello,
> does anyone know what could be wrong? There's a lot of similar entries
> in the SQL Server current log:
> 2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'
> There are hundreds of similar entries that repeat every few seconds. The
> database works quite slowly and the users get 'Connection timeout'
> message very often.
> Thanks for any advice.
> ..:: fabio
>|||Uncheck 'AUTO CLOSE' on the database properties options page. (Right click
database name in Enterprise Mangler, select Properties, click on Options
tab.
--
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
"Fabio" <fabio@.anti-spam.inet.alpha.pl> wrote in message
news:bumc1f$2hu$1@.atlantis.news.tpi.pl...
> Hello,
> does anyone know what could be wrong? There's a lot of similar entries
> in the SQL Server current log:
> 2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'
> 2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'
> There are hundreds of similar entries that repeat every few seconds. The
> database works quite slowly and the users get 'Connection timeout'
> message very often.
> Thanks for any advice.
> ..:: fabio
>|||Fabio wrote:
Thanks a lot, Dejan and Geoff.
After turning the 'auto close' option the database works much faster and
the messages about database starting don't appear in the error log.
..:: fabiosql

Saturday, February 25, 2012

Cube members not accurate

What could gone wrong when the memebers of a dimension after deployment is not accurrate as the actual records in the Dim table? Initially i hit an error when changing the actual Dim table and Fact table ( by the way i am changing the primary foreign key values.) Then i ecounter errors when trying to process the cube again. Seeing this:http://support.microsoft.com/kb/922673 , I recreate the data source and no errors after the deployment 9 hurray). But the new records added in the Dim is not reflected in the memebers of the cube :(

I guess the initial error that I get is becausethe Dim table is not updated in thefirst place causing the Fact table to have keys not found in Dim. But my question is why is it theDim not updated?

Thanks.

Regards

Alu

Go back try processing your dimension using standard processing options.

If you instruct Analysis Server to hide problems it finds during dimension processing, you never going to find problems you have in your data. The instructions in the KB article only let you get by if you are just in the hurry to get your cube somehow processed. You should really try and resolve all the problems with relational data to see the correct dimension structure and correct measure totals. Hiding processing errors is quite dangerous.

Edward Melomed.
--
This posting is provided "AS IS" with no warranties, and confers no rights.