Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Thursday, March 29, 2012

Distributed Broker Queue Performance Issue

Hi,

We are doing a POC for transferring a huge number of messages(millions) from oner machine to another. The two approaches we are examining are MSMQ and SQL Broker. The MSMQ is set up as a remote queue on the target machine, and the source machine takes as little as 1 millisecond to send the message (using a .NET program). However, when testing on Service Broker, we find that the time taken to send message to the queue is significantly higher - like 70 millisecond. Could you please help us in understanding why this is happening?

The service broker distributed queues have been set up as per the directions in the posting at http://www.sqlservercentral.com/columnists/sindukuri/2797.asp

The source program (written in .NET) is calling a stored procedure in the source machine to write to the SSB queue. When we run SQL Trace, we find that the SP is responsible for 99% of the time taken. Here is our SP that send the message:

Declare @.ConversationHandle uniqueidentifier
Begin Dialog @.ConversationHandle
From Service SenderService
To Service 'ReceiverService'
On Contract SampleContract
WITH Encryption=off;
SEND
ON CONVERSATION @.ConversationHandle
Message Type SenderMessageType
(<<XML String>>)

Please let us know if there are any additional settings required in the Service Broker to improve its performance. Or , what are the other approaches for building a distributed SSB application?

How big are the messages?
Are you using transactional MSMQ?

70 ms per message means ~15 msgs per second, that is quite slow. The most basic setup w/o any optimization is usualy be around 200 msgs/sec (with 1k payload) and an optimal setup should drive ~4000 msgs/sec on comodity hardware (ie. .5 milliseconds per message). Of course, I'm talking fully transacted, remote delivery operations. Have you done the minimal optimizations needed for any database operations (eg. separate data and log files on separte spindles) ?

Sending one message per dialog will give you the worst performance in SSB, both on the sending side (you need to to add the cost of the END CONVERSATION messages) as well as from the point of view of processing the messages. Have a look at the slides at http://blogs.msdn.com/remusrusanu/archive/2007/04/03/orlando-slides-and-code.aspx for a comparison of one-message-per-conversation vs. resusing conversations, as well as to see the very basic optimizations you can apply to SSB operations.

Besides raw performance, the SSB semantics (dialogs/conversartions) are quite different from MSMQ. SSB provides full duplex exactly-once-in-order reliable delivery with well defined error semantics, while MSMQ provides just raw messaging (think TCP vs. UDP if you're familiar with IP network programming).|||

The messages are close to 1 K - these are simple XML strings. We are using transactional MSMQ, and transactional SSB. These transactions are created within the .NET program, and the SQL Stored Procedure does not contain any transactions. The logic is very simple - we have a loop in C#, that reads data from anothe table (and stores in a datareader), create XML representation of that data, and calls a Stored Procedure which contains the Send Statement. I examined the links that you provided - I understand that it is possible to delay the Commit by using loop counts. However, in our case, since there are separate transactions for each message, what we can do to improve throughput?

Regards

Prasanth

|||The problem is your performance of communicating from .Net application to SQL Server. You basically cannot feed more than 15 messages per second (15 T-SQL batches), so SSB has nothing else to transmit more than 15 messages per second. Anything you can do improve this will help the message rate: cumulate several calls into a single one to reduce the number of round trips, use parametrized queries, anything that applies generic .Net T-SQL programming applies to SSB as well.
If you cannot reduce the number of transaction commits, a faster spindle for the database LDF will help. Of course, separate MDF and LDF on separate spindles.

Tuesday, March 27, 2012

Distrib agent question

From BOL
CommitBatchThreshold 1000 The number of replication commands to be
issued to the Subscriber before a COMMIT statement is issued.
So if the distrib agent report 1 transaction with 100,000 commands are
replicated, i guess the above CommitBatchThreshold of 1000 does not apply..
right ? It appears that it commits only after the 100,000 commands make it
to the subscriber . Am I right ? Can i commit on the subscriber 1000
commands at a time ?
Not really, one commit will be called. One commit will occur in increments
of 1000, so one commit will be called from 1 to 1000 transactions. For 1001
to 2000 there will be 2, 2000>3000 3, etc.
The commit is done on a per transaction basis as opposed to a per command
basis.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:%232IwOPmYFHA.2076@.TK2MSFTNGP15.phx.gbl...
> From BOL
> CommitBatchThreshold 1000 The number of replication commands to be
> issued to the Subscriber before a COMMIT statement is issued.
>
> So if the distrib agent report 1 transaction with 100,000 commands are
> replicated, i guess the above CommitBatchThreshold of 1000 does not
> apply..
> right ? It appears that it commits only after the 100,000 commands make it
> to the subscriber . Am I right ? Can i commit on the subscriber 1000
> commands at a time ?
>
|||I have 1 transaction with 100,000 commands..
Do you mean it will commit 1000 commands at a time..
Im a lil confused as your message indicates transactions and not commands
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:O4Y1LzRZFHA.2768@.tk2msftngp13.phx.gbl...
> Not really, one commit will be called. One commit will occur in increments
> of 1000, so one commit will be called from 1 to 1000 transactions. For
1001[vbcol=seagreen]
> to 2000 there will be 2, 2000>3000 3, etc.
> The commit is done on a per transaction basis as opposed to a per command
> basis.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "Hassan" <fatima_ja@.hotmail.com> wrote in message
> news:%232IwOPmYFHA.2076@.TK2MSFTNGP15.phx.gbl...
it
>
|||The way I read it: one commit, no matter how many commands per transaction.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uaN5P6SZFHA.1368@.tk2msftngp13.phx.gbl...[vbcol=seagreen]
> I have 1 transaction with 100,000 commands..
> Do you mean it will commit 1000 commands at a time..
> Im a lil confused as your message indicates transactions and not commands
> "Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
> news:O4Y1LzRZFHA.2768@.tk2msftngp13.phx.gbl...
increments[vbcol=seagreen]
> 1001
command[vbcol=seagreen]
be[vbcol=seagreen]
are[vbcol=seagreen]
make
> it
>

Sunday, March 25, 2012

DISTINCT PROBLEM

i have two fields. One is id (otomatic number) and another is email..
there are some duplicate records in email records.
I want to use distinct query for email field to eliminate duplicate
records..I also want to get id fields of resultset of distinct email.
I thought that there are more than one id value for duplicate records. Can i
get max or min id valure of duplicate records or what algorithm sql server
does use ?Maybe something like...
SELECT email, MAX([ID]) AS [ID]
FROM table
GROUP BY email
ORDER BY email
HTH,
Ben
"Savas Ates" <in da club> wrote in message
news:OtQCQLyNGHA.916@.TK2MSFTNGP10.phx.gbl...
>i have two fields. One is id (otomatic number) and another is email..
> there are some duplicate records in email records.
> I want to use distinct query for email field to eliminate duplicate
> records..I also want to get id fields of resultset of distinct email.
> I thought that there are more than one id value for duplicate records. Can
> i
> get max or min id valure of duplicate records or what algorithm sql server
> does use ?
>|||Untested...
Select A.ID, A.EMAIL from MYTABLE A
where exists (select 1 from MYTABLE B
where B.EMAIL = A.EMAIL
and B.ID < A.ID)
This should select all rows with duplicate EMAIL except for the EMAIL with
the lowest numbered ID.
You could also use:
select A.EMAIL, count(*) from MYTABLE A
group by A.EMAIL
having COUNT(*) > 1
Which will give you a list of all EMAILs occuring more than once, along with
how many times they occur. After you ge the data cleaned up you can add a
unique constraint which will prevetn duplicate emails from getting inserted
in the future.
"Savas Ates" <in da club> wrote in message
news:OtQCQLyNGHA.916@.TK2MSFTNGP10.phx.gbl...
> i have two fields. One is id (otomatic number) and another is email..
> there are some duplicate records in email records.
> I want to use distinct query for email field to eliminate duplicate
> records..I also want to get id fields of resultset of distinct email.
> I thought that there are more than one id value for duplicate records. Can
i
> get max or min id valure of duplicate records or what algorithm sql server
> does use ?
>sql

Distinct insert

I am trying to insert a record id primary at the same time that I am trying
to insert a Distinct Account number.
The insert statement is something kind of like this:
insert into Accounts (AccountsOID,Account)
select Distinct "Rec NO" + 100 as AccountsOID, "LIC TAG" as Account from
AutoExpt
In the AutoExpt table there are multiple occurrences of "LIC TAG" values all
of which need to be put into the Accounts table, however there must be only
one entry for the Lic tag in the accounts table. The Rec No +100 is just to
create a unique primary key for the AccountsOID.
Is there anyway I can get only the Distinct Lic Tag's, but at the same time
get a unique primary key for them.
Thanks,
On Wed, 25 Aug 2004 12:55:03 -0700, Robert wrote:

>I am trying to insert a record id primary at the same time that I am trying
>to insert a Distinct Account number.
>The insert statement is something kind of like this:
>insert into Accounts (AccountsOID,Account)
>select Distinct "Rec NO" + 100 as AccountsOID, "LIC TAG" as Account from
>AutoExpt
>In the AutoExpt table there are multiple occurrences of "LIC TAG" values all
>of which need to be put into the Accounts table, however there must be only
>one entry for the Lic tag in the accounts table. The Rec No +100 is just to
>create a unique primary key for the AccountsOID.
>Is there anyway I can get only the Distinct Lic Tag's, but at the same time
>get a unique primary key for them.
>Thanks,
Hi Robert,
Please provide DDL (CREATE TABLE statements, with constraints), sample
data (as INSERT statements), expected output and a description of the
business problem you're trying to solve.
http://www.aspfaq.com/etiquette.asp?id=5006
http://vyaskn.tripod.com/code.htm#inserts
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Unfortunately I do not have the create table SQL statements
What I am trying to accomplish is importing data from an excel file into a
SQL database. To make it easier to work with I simply straight imported the
excel file into a new table in the SQL database (AutoExpt). Accounts is one
of the tables that I need to import into. I do know that the OID for the
accounts table is not automatically generated, and must be generated manually.
In the AutoExpt table there is a listing of vechiles and what accounts
maintenance should be charged to. I can add the vechiles fine to the
Equipment table (Not listed here because it works just fine). However another
table EquipmentFeature is linked to the Equipment table. It contains things
such as account numbers, and the department that the vechile belongs to.
From what I can tell I can not add records to the Equipment feature table
such as the account number because they do not exist in the Accounts table.
So the solution is to first add all the distinct account numbers into the
accounts table. This also applies to the departments table as well.
I do have a backup of the database so I can fool aroudn with it all I want
without worry of data loss or damage, plus I am working on a dev server so no
actual users are accessing the database. I found that I can add duplicate
records in the accounts table and the departments table, however I have found
that I can't remove some duplicates in the departments table because it
claims that a record needs to exist in the General table first.
My theory is that if I add only the distinct account numbers and departments
I should be fine, and it should stop telling me that "A record must exist in
the accounts table first"
Unfortunately the company that makes the software is not offering much
support on importing the data. So I am left to figure it out myself.
"Hugo Kornelis" wrote:

> On Wed, 25 Aug 2004 12:55:03 -0700, Robert wrote:
>
> Hi Robert,
> Please provide DDL (CREATE TABLE statements, with constraints), sample
> data (as INSERT statements), expected output and a description of the
> business problem you're trying to solve.
> http://www.aspfaq.com/etiquette.asp?id=5006
> http://vyaskn.tripod.com/code.htm#inserts
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>
|||On Thu, 26 Aug 2004 05:55:04 -0700, Robert wrote:

>Unfortunately I do not have the create table SQL statements
(snip)
Hi Robert,
Did you read the links I posted in my message? They contain instructions
on how you can generate the create table statements from the existing
tables (the ewb site shows how it's done with Query Analyzer; there's an
option to generate SQL in Enterprise Manager as well).
I read your description, but I can't figure out what you're trying to do
and what problems you are trying to tackle. I really need the table
structure and sample data to understand your problem.
(BTW, if therre are legal or other issues that prohibit you from posting
the table structure, you may also create a fake table that recreates the
problem).
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||I can't post the structure or data because it's against our policies. I can
provide you something that looks similair. I basically need to be able to
insert only the unique account numbers from one table into another table,
however at the same time inserting a unique primary key into the same
destination table.
For example I kinda have something like this:
Primary Key From Table 1, Account Number
1,A
2,A
3,B
4,C
5,B
I need to put that information in a seperate table that is similair to this:
Primary From table2, Account Number
-564564,K
564578,D
7246,S
54567,F
The second table can not have any duplicate account numbers and of course
the Primary key.
What I want to do is select from table1 something looking like this:
Primary Key From Table 1, Account Number
1,A
3,B
4,C
Leaving me only with unique primary keys and account numbers.
The end result for table2 should look something like this:
-564564,K
564578,D
7246,S
54567,F
1,A
3,B
4,C
"Hugo Kornelis" wrote:

> On Thu, 26 Aug 2004 05:55:04 -0700, Robert wrote:
> (snip)
> Hi Robert,
> Did you read the links I posted in my message? They contain instructions
> on how you can generate the create table statements from the existing
> tables (the ewb site shows how it's done with Query Analyzer; there's an
> option to generate SQL in Enterprise Manager as well).
> I read your description, but I can't figure out what you're trying to do
> and what problems you are trying to tackle. I really need the table
> structure and sample data to understand your problem.
> (BTW, if therre are legal or other issues that prohibit you from posting
> the table structure, you may also create a fake table that recreates the
> problem).
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>
|||On Thu, 26 Aug 2004 08:39:12 -0700, Robert wrote:

>I can't post the structure or data because it's against our policies. I can
>provide you something that looks similair. I basically need to be able to
>insert only the unique account numbers from one table into another table,
>however at the same time inserting a unique primary key into the same
>destination table.
>For example I kinda have something like this:
>Primary Key From Table 1, Account Number
>1,A
>2,A
>3,B
>4,C
>5,B
>I need to put that information in a seperate table that is similair to this:
>Primary From table2, Account Number
>-564564,K
>564578,D
>7246,S
>54567,F
>The second table can not have any duplicate account numbers and of course
>the Primary key.
>What I want to do is select from table1 something looking like this:
>Primary Key From Table 1, Account Number
>1,A
>3,B
>4,C
>Leaving me only with unique primary keys and account numbers.
>The end result for table2 should look something like this:
>-564564,K
>564578,D
>7246,S
>54567,F
>1,A
>3,B
>4,C
Hi Robert,
The following is untested as I only test solutions I provide in newsgroups
if I can copy and paste CREATE TABLE and INSERT statements. I like solving
problems and helping people, but I detest typing - I have to do plenty of
typing in my job :-)
But try if this gives you what you need:
INSERT INTO table2 (PrimKeyFromTable2, AccountNumber)
SELECT MIN(PrimKeyFromTable1), AccountNumber
FROM Table1
GROUP BY AccountNumber
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||That did the trick, I should have thought about grouping them.
Hugo... Your a genius!
Thanks,
"Hugo Kornelis" wrote:

> On Thu, 26 Aug 2004 08:39:12 -0700, Robert wrote:
>
> Hi Robert,
> The following is untested as I only test solutions I provide in newsgroups
> if I can copy and paste CREATE TABLE and INSERT statements. I like solving
> problems and helping people, but I detest typing - I have to do plenty of
> typing in my job :-)
> But try if this gives you what you need:
> INSERT INTO table2 (PrimKeyFromTable2, AccountNumber)
> SELECT MIN(PrimKeyFromTable1), AccountNumber
> FROM Table1
> GROUP BY AccountNumber
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>

Thursday, March 22, 2012

Distinct count problem

Hi,

I'm trying to create a measure (distinct count) for counting the number of stores which sell product. I used to fact table to count store_key but I've just realized this measure returns a count including stores which do not sell the product.

Daily Sales fact : store_key, net sales dollars .....

How should I define the calc in this case? I'm thinking conditional statements but not clear yet.

Please give me some comments. Thanks.

We do something similar - a count of invoices that have a coupon applied to them. There are two ways (that I know of) to do this:

1) at the fact level. Have a measure in your fact table that contains a 1 or 0 for each store that sells the product. Not a very efficient way, but it will get the job done. Do a sum on this measure. Depending on how you want to count your products, you could have a measure group that is store_key, product_key, sells_product (int). This will work, but definitely not efficient.

2) The way we do it is to make the item you are measuring an attribute of the dimension itself. In our case we have an invoice dimension which contains a "has_coupon" attribute. As part of the ETL we determine if the value of has_coupon shoud be "Yes" or "No". You then can query according to the values of this attribute. We then can do [Invoice].[Has Coupon].Children.Count, or any other derivation of it.

I would recommend option #2, but it all depends on your situation. If anyone else knows of other ways to model, I'm curious too.

Good luck,

John Hennesey

|||Not totally clear, but is it counting a NULL value when you don't want it to?

Just create another fact table in the DSV based off of the fact table where the key is not null:

select *
from fact
where
key is not null

And create the DISTINCT COUNT measure based of this new new table.
|||

thanks.

it's easy and it works fine Smile

sql

Distinct Count in a new Measure Group

Here is the situation:

I have a cube that has transaction level data and there is a control number that goes with this data, but it isn't one for one. If I have 60 million rows in the fact table, I have 50 million control numbers in a control number dimension.

I would like to be able to slice the data by date (for instance) and then do a distinct count on the control number dimension. I can do a distinct count w.o having to do a join of course because I can count the distinct instances of the key to the control number dimension.

One more note - the control number dimension is not a degenerate dimension...it is not one to one on the fact table.

I would like to use the DISTINCT COUNT measure in SSAS, but it makes me create a new measure group to do so. All of my additive measures are in one group, the distinct count is forced into another group. This forces double the processing time.

Does anyone know why this behavour happens and can someone explain why a DISTINCT COUNT measure has to go in a seperate measure group?

Thanks,

Mark

Mark,

Do you already have a DISTINCT COUNT measure in that measure group? Analysis Services will only allow you to have one DISTINCT COUNT per measure group.

|||Maybe this MDX will overcome the limitation of one unqiue count.

Distinct(Filter([Customer].[Customer Name].Members,Not IsEmpty([Measures].[Sales Amount]))).Count

Timmy|||

Actually, I don't have one in the first measure group. The first measure group is just regular measures, but if I create a new measure that is a distinct count measure, it automatically puts it in another group.

I have now heard from other sources that this is an exptected behavior. So no biggie, just needed to know.

ps - sorry it took so long to respond.

Thanks,

Mark

http://spaces.msn.com/mgarnerbi

|||I noticed this too, does anyone know the underlying reason why this is? Is this going to be fixed in a future version?sql

Distinct Count in a new Measure Group

Here is the situation:

I have a cube that has transaction level data and there is a control number that goes with this data, but it isn't one for one. If I have 60 million rows in the fact table, I have 50 million control numbers in a control number dimension.

I would like to be able to slice the data by date (for instance) and then do a distinct count on the control number dimension. I can do a distinct count w.o having to do a join of course because I can count the distinct instances of the key to the control number dimension.

One more note - the control number dimension is not a degenerate dimension...it is not one to one on the fact table.

I would like to use the DISTINCT COUNT measure in SSAS, but it makes me create a new measure group to do so. All of my additive measures are in one group, the distinct count is forced into another group. This forces double the processing time.

Does anyone know why this behavour happens and can someone explain why a DISTINCT COUNT measure has to go in a seperate measure group?

Thanks,

Mark

Mark,

Do you already have a DISTINCT COUNT measure in that measure group? Analysis Services will only allow you to have one DISTINCT COUNT per measure group.

|||Maybe this MDX will overcome the limitation of one unqiue count.

Distinct(Filter([Customer].[Customer Name].Members,Not IsEmpty([Measures].[Sales Amount]))).Count

Timmy
|||

Actually, I don't have one in the first measure group. The first measure group is just regular measures, but if I create a new measure that is a distinct count measure, it automatically puts it in another group.

I have now heard from other sources that this is an exptected behavior. So no biggie, just needed to know.

ps - sorry it took so long to respond.

Thanks,

Mark

http://spaces.msn.com/mgarnerbi

|||I noticed this too, does anyone know the underlying reason why this is? Is this going to be fixed in a future version?

Distinct Count in a new Measure Group

Here is the situation:

I have a cube that has transaction level data and there is a control number that goes with this data, but it isn't one for one. If I have 60 million rows in the fact table, I have 50 million control numbers in a control number dimension.

I would like to be able to slice the data by date (for instance) and then do a distinct count on the control number dimension. I can do a distinct count w.o having to do a join of course because I can count the distinct instances of the key to the control number dimension.

One more note - the control number dimension is not a degenerate dimension...it is not one to one on the fact table.

I would like to use the DISTINCT COUNT measure in SSAS, but it makes me create a new measure group to do so. All of my additive measures are in one group, the distinct count is forced into another group. This forces double the processing time.

Does anyone know why this behavour happens and can someone explain why a DISTINCT COUNT measure has to go in a seperate measure group?

Thanks,

Mark

Mark,

Do you already have a DISTINCT COUNT measure in that measure group? Analysis Services will only allow you to have one DISTINCT COUNT per measure group.

|||Maybe this MDX will overcome the limitation of one unqiue count.

Distinct(Filter([Customer].[Customer Name].Members,Not IsEmpty([Measures].[Sales Amount]))).Count

Timmy
|||

Actually, I don't have one in the first measure group. The first measure group is just regular measures, but if I create a new measure that is a distinct count measure, it automatically puts it in another group.

I have now heard from other sources that this is an exptected behavior. So no biggie, just needed to know.

ps - sorry it took so long to respond.

Thanks,

Mark

http://spaces.msn.com/mgarnerbi

|||I noticed this too, does anyone know the underlying reason why this is? Is this going to be fixed in a future version?

DISTINCT Count and NULL Processiong

In short, I have a measure that counts the distinct number of customers.

I recently learned that it's counting a NULL value as 1 and I don't want this. Are there some properties that can stop the NULL value from being counted? I tried playing with a few of the properties that I found, but no luck.

The only solution that I have thought of so far is creating another table in the DSV that explicitly filters out the NULL values in the WHERE clause and then using it as the source for the DISTINCT COUNT. However, I'd like to avoid this solution if possible.

Maybe some MDX in a Calculated Member is needed? If so, please provide the pseudo-MDX as my MDX is definitely weak.

Any thoughts?

By the way, it's a AS2005 cube using SQL 2005 Standard Edition.

How about creating a new, hidden dimension (or attribute on your customer dimension) with two members: one member represents rows in the fact table where your Customer is null, and one for where it's not null. What you could then do is keep your distinct count measure as it is, but then overwrite it in the MDX Script so it only returns the value for the not-null member - something like this:

(Measures.[Customer Count])=(Measures.[Customer Count], [Hidden Dimension].[Hidden Attribute].[Not Null Customers]);

HTH,

Chris

|||Or, even better, make [Not Null Customers] member to be a default member in that dimension, and then you won't need to do anything in MDX Script at all, and it will be better for performance. My preference, however, is to do the DSV change that you want to avoid, I think that is the best solution.

DISTINCT Conflicting with my query

I need p.phonenumber in there but then it messes up my DISTINCT ON m.number because I end up with dup m.numbers if I run just the inner select statement during testing.
But then I need the phonenumber in that subquery so that I can do list.phonenumber
ahh!

UPDATE Master

SET master.homephone = list.phonenumber

FROM MASTER m

INNER JOIN

(SELECT DISTINCT p.number, topphone.phonenumber

FROM phones p

INNER JOIN (SELECT top 1 phonenumber from phones) as topphone ON topphone.number = p.number

WHERE p.phonetypeID = 1

AND ISNULL(p.good, 0) <> 0

AND LEN(p.phonenumber) = 10

) AS list ON m.Number = list.Number

WHERE m.homephone IS NULL OR m.homephone = ''


Error:
Msg 156, Level 15, State 1, Procedure Skiaa, Line 66
Incorrect syntax near the keyword 'top'.
Msg 156, Level 15, State 1, Procedure Skiaa, Line 88
Incorrect syntax near the keyword 'top'.
I want to update m.homephone with the p.phonenumber based in the filtering critiria I have specified but this simple task is turning out to be a pain.

Without actually trying to recreate the tables on my local server, I'll try to answer this. This is assuming it's actually something wrong with evaluating the top function within your derived table structure.

Anyway, try something like this instead...

UPDATE Master

SET master.homephone = list.phonenumber

FROM MASTER m

INNER JOIN

(SELECT DISTINCT p.number, topphone.phonenumber

FROM phones p

WHEREp.phonetypeID = 1

AND ISNULL(p.good, 0) <> 0

AND LEN(p.phonenumber) = 10

AND p.number = (SELECT TOP 1 phonenumber from phones)

) AS list ON m.Number = list.Number

WHERE m.homephone IS NULL OR m.homephone = ''

OR...

DECLARE @.max_phone NVARCHAR(100)
SET @.max_phone = (SELECT TOP 1 phonenumber from phones)

UPDATE Master

SET master.homephone = list.phonenumber

FROM MASTER m

INNER JOIN

(SELECT DISTINCT p.number, topphone.phonenumber

FROM phones p

WHEREp.phonetypeID = 1

AND ISNULL(p.good, 0) <> 0

AND LEN(p.phonenumber) = 10

AND p.number = @.max_phone) AS list ON m.Number = list.Number

WHERE m.homephone IS NULL OR m.homephone = ''

Monday, March 19, 2012

Displaying Total number of Rows in a Report in Page Header.

Hi,

I have requirement to display Total number of Rows in a Report in Page Header.

I have written the following code in Page header it shows RowCount for the Page only.

=Count(ReportItems!textboxInTableCell.Value)

Can anyone please help on this?

Regards

Raghav

By Total number of reports in the report do you mean the number of rows returned by the Dataset query? If so, add a textbox in your Report Body with the expression =CountRows("DataSet1") with the name of your Dataset in place of DataSet1.

Then refer to this textbox directly in the Page Header.

This should give you the total row count for your Dataset.

-Aayush

|||

Thanks aayush,

I used =CountRows() in body header and set the RepeatWith property to "tableName" and it works as Page header.

Regards

Raghavendra

Displaying the row number in a query

Hi,
My query is retrieving rows from a table.
All what I need is to display the row number which is simply a consecutive number.
Can any one advise me if there is a direct thing to do this in the SELECT stmt?
I can do it through creating a temp table then add IDENTITY column pla pla pla ..I need a direct way through the query itself.
In Oracle I can use RowNum in the query.

Thanks in advance for all.Is it not doable?

Originally posted by RaedT
Hi,
My query is retrieving rows from a table.
All what I need is to display the row number which is simply a consecutive number.
Can any one advise me if there is a direct thing to do this in the SELECT stmt?
I can do it through creating a temp table then add IDENTITY column pla pla pla ..I need a direct way through the query itself.
In Oracle I can use RowNum in the query.

Thanks in advance for all.|||The short answer is NO. TSQL operations are set based, and no ordering is guaranted by the server unless the developer or programmer specifies it, thus row numbering is pointless because the same query run on two different occasions could result in the same record being assigned different row numbers.

The long answer is YES, if your result set is sorted by a unique key or combination of columns, then you can write a Select statement that loops back on itself and counts the number of records less than each record. This is an expensive query to run and can be difficult to debug, so my recommendation to you would be to use a temporary table (actually, a table variable is more efficient) as long as it suits your needs.

Why do you need the results numbered? While there are some circumstances where this is beneficial, it is often a sign of problems with the database schema or the application design concept.

blindman|||If you don't have already a client, I may consider to put your SELECT statement in the software of a (ADO) client, where you can make use of the AbsolutePosition property of a recordset.

Sunday, March 11, 2012

Displaying Remainders

I need to show the whole number and remainder each as wole numbers. I have been trying to use modulo on the advice from a friend, but I don't understand this function.

More of an exlpanition: I am working with inventory and shipping quantities. If a pallet consists of 9 cases, and I have an order for 20 cases, I need to display in a report 2 pallets and 2 cases. These numbers can be in the same column or different columns...at this point I just need to be able to display the numbers.

Is there any way to do this? Any help would be appreciated.

-Thanks

P.S.

I posted this in the general forums before I realized I was there...not sure how to move posts, so I double-posted....sorry.

Hello,

Try this:

=cStr(cInt(Fields!CasesOrdered.Value / Fields!CasesOnPallet.Value)) + " Pallets " + cStr(Fields!CasesOrdered.Value Mod Fields!CasesOnPallet.Value) + " Cases"

Hope this helps.

Jarret

|||

This is what I need. Thanks

On this solution, how do I force a round down on the "Pallet" number (18.66667 is showing as 19 but needs to show as 18)?

I tried this:

=cStr(Floor(cInt(Fields!CasesOrdered.Value / Fields!CasesOnPallet.Value))) + " Pallets " + cStr(Fields!CasesOrdered.Value Mod Fields!CasesOnPallet.Value) + " Cases"

But this didn't change anything.

What are your thoughts?

-EDIT-

I used the cInt to remove the decimals

=cStr(Floor(cInt(Fields!CasesOrdered.Value / Fields!CasesOnPallet.Value))) + " Pallets " + cStr(cInt(Fields!CasesOrdered.Value Mod Fields!CasesOnPallet.Value)) + " Cases

|||

Try this:

=cStr(Floor(Fields!CasesOrdered.Value / Fields!CasesOnPallet.Value)) + " Pallets " + cStr(cInt(Fields!CasesOrdered.Value Mod Fields!CasesOnPallet.Value)) + " Cases

I should have used the Floor function on the Pallets calculation (instead of cInt). Then, the cInt on the Cases will remove the decimals.

Hope this helps.

Jarret

|||Perfect! Everything works exactly like is should now. Thanks for your henp.

Displaying only a fixed number of Columns in Matrix

Is it possible to display only a certain number of columns in a matrix, say the first 6 and then hide the rest? That is, does the matrix allow to somehow control how many columns can be displayed from a column group and hide the remaining columns (I need this to limit the number of columns a user is able to see so that the matrix width does not get infinitely long).

In other words.....

I need to display the subtotals for all dynamically generated columns but display only first 6 columns. This way I can avoid having to display 50 columns and not have user scroll to so far right and keep the page width within reasonable limits. Hope I have made it clear.

Thanks.

I did something like this. If you know that 6 columns will fill the width then you can return the (total amount of known columns / 6) as a page count.

Use the page count variable to hide/unhide a set of labels on top of the report. When a page label is clicked call the same report with the selected page as a parameter.

This will work if you can segment the result set based on a your page range in the database.

|||

Hmmm... That may not be exactly what I am looking for. Ideally, it would be nice if one can go into Group->Edit Column Group and set some property such as "# of Columns to Display for this Column Group" and behind the scenes it didn't care whether or not you bring in 6 columns from the DB or 600.

I hope there is a simpler solution or workaround to this.

|||Any body plz.. any ideas how to achieve this either in sql or through matrix formatting?

Displaying only a fixed number for Columns in Matrix

Is it possible to display only a certain number of columns in a matrix, say the first 6 and then hide the rest? That is, does the matrix allow to somehow control how many columns can be displayed from a column group and hide the remaining columns (I need this to limit the number of columns a user is able to see so that the matrix width does not get infinitely long).

In other words.....

I need to display the subtotals for all dynamically generated columns but display only first 6 columns. This way I can avoid having to display 50 columns and not have user scroll to so far right and keep the page width within reasonable limits. Hope I have made it clear.

Thanks.

I did something like this. If you know that 6 columns will fill the width then you can return the (total amount of known columns / 6) as a page count.

Use the page count variable to hide/unhide a set of labels on top of the report. When a page label is clicked call the same report with the selected page as a parameter.

This will work if you can segment the result set based on a your page range in the database.

|||

Hmmm... That may not be exactly what I am looking for. Ideally, it would be nice if one can go into Group->Edit Column Group and set some property such as "# of Columns to Display for this Column Group" and behind the scenes it didn't care whether or not you bring in 6 columns from the DB or 600.

I hope there is a simpler solution or workaround to this.

|||Any body plz.. any ideas how to achieve this either in sql or through matrix formatting?

Displaying Number of Table Fields Based on Database Values

Hi guys,

I have this problem here. I have this database with fields LB1, LB2, LB3, LB4 and LB5. Each of these fields have their own respective values. I have another database field called ANSCODE to control the number of fields being displayed.

If the value of ANSCODE is 4, I will have to display fields LB1 to LB4. If the value of ANSCODE is 5, i will have to display fields LB1 to LB5. Can this be achieved with a table? Can someone enlighten me on this? Thanks.

Cheers,

Do you have one value for ANSCODE for the entire report, or different values for each detail row? If it's the former, you can define a table with five columns, then based on the value of ANSCODE, hide the column which shows LB5, i.e. set the hidden property on the table column to "=IIF(Fields!ANSCODE.Value=4, true, false)".

If it's the latter, you might have different number of fields shown in different table rows? In that case, you can hide the textbox for LB5 using the same expression above.

|||

look at this link perhaps it' will help you

http://www.codeproject.com/dotnet/DynamicReport.asp?df=100&forumid=205933&exp=0&select=1195355

Displaying Number of Table Fields Based on Database Values

Hi guys,

I have this problem here. I have this database with fields LB1, LB2, LB3, LB4 and LB5. Each of these fields have their own respective values. I have another database field called ANSCODE to control the number of fields being displayed.

If the value of ANSCODE is 4, I will have to display fields LB1 to LB4. If the value of ANSCODE is 5, i will have to display fields LB1 to LB5. Can this be achieved with a table? Can someone enlighten me on this? Thanks.

Cheers,

Do you have one value for ANSCODE for the entire report, or different values for each detail row? If it's the former, you can define a table with five columns, then based on the value of ANSCODE, hide the column which shows LB5, i.e. set the hidden property on the table column to "=IIF(Fields!ANSCODE.Value=4, true, false)".

If it's the latter, you might have different number of fields shown in different table rows? In that case, you can hide the textbox for LB5 using the same expression above.

|||

look at this link perhaps it' will help you

http://www.codeproject.com/dotnet/DynamicReport.asp?df=100&forumid=205933&exp=0&select=1195355

Displaying Number Format As Per The Regional Settings in Crystal Report

Sir,
I am Using Crystal report 10.
How to Display The Number Format as like The Regional Setting in The computer.
After Changing The Regional Settings, I Changed The Number Format to The System Default Format...But It is Not Working...
Plz Help meHi There,
Can you please let me know if you found solution to this problem? We have the same problem in our reports. We cannot use formula fields as we have close to 60 reports and converts all fields to formula fields would not be possible.
Thanks in advance

Friday, March 9, 2012

displaying extra characters with COLUMN-defined number format?

Here's a tricky SQL question that has definitely driven me to the end of
my rope. I'm using Oracle 9i and I need to perform some simple
multiplication on a field and then display it with a percent sign using
the COLUMN command. Here's the code thus far:

COLUMN price format 9,999.99 HEADING 'Charged%'
SELECT pricecharged * .231 as price
FROM VT_examdetail

The output from this reads:

Charged%
---
23.10
34.65
34.65
...

The kicker here is that I need to add a percent sign to the right of the
output, so that it reads:

Charged%
---
23.10%
34.65%
34.65%
...

I thought I could do this by just adding "|| ('%')" into the SELECT
statement, but when I do this the decimal position defined in the COLUMN
command is lost. Does anyone know another way around this?

Thanks,
AlexOn Tue, 07 Oct 2003 08:58:56 -0700, Alex <raindogs_1@.yahoo.com> wrote:

>Here's a tricky SQL question that has definitely driven me to the end of
>my rope. I'm using Oracle 9i and I need to perform some simple
>multiplication on a field and then display it with a percent sign using
>the COLUMN command. Here's the code thus far:
>COLUMN price format 9,999.99 HEADING 'Charged%'
>SELECT pricecharged * .231 as price
>FROM VT_examdetail
>The output from this reads:
> Charged%
>---
> 23.10
> 34.65
> 34.65
>...
>
>The kicker here is that I need to add a percent sign to the right of the
>output, so that it reads:
>
> Charged%
>---
> 23.10%
> 34.65%
> 34.65%
>...
>I thought I could do this by just adding "|| ('%')" into the SELECT
>statement, but when I do this the decimal position defined in the COLUMN
>command is lost. Does anyone know another way around this?
>Thanks,
>Alex
TO_CHAR(number, '99.99') || '%'|||Hi,

You could do this:

select cast( charged as varchar(10)) + '%' from orders

Regards,
-Manoj|||"Alex" <raindogs_1@.yahoo.com> wrote in message
news:3F82E2C0.4030204@.yahoo.com...
> Here's a tricky SQL question that has definitely driven me to the end of
> my rope. I'm using Oracle 9i and I need to perform some simple
> multiplication on a field and then display it with a percent sign using
> the COLUMN command. Here's the code thus far:

Couple of comments, this is a ms-sqlserver forum, not Oracle.

However, the other answers should work.

But, I'd say you're going about this the wrong way. Formatting should be
done at an entirely different level than the DB.

> COLUMN price format 9,999.99 HEADING 'Charged%'
> SELECT pricecharged * .231 as price
> FROM VT_examdetail
> The output from this reads:
> Charged%
> ---
> 23.10
> 34.65
> 34.65
> ...
>
> The kicker here is that I need to add a percent sign to the right of the
> output, so that it reads:
>
> Charged%
> ---
> 23.10%
> 34.65%
> 34.65%
> ...
> I thought I could do this by just adding "|| ('%')" into the SELECT
> statement, but when I do this the decimal position defined in the COLUMN
> command is lost. Does anyone know another way around this?
> Thanks,
> Alex

Wednesday, March 7, 2012

Displaying Auto Sequence Number

I want to write the sql query for displaying sequence number in the result..
.
E.g.
SeqNo Col1 Col2
==== === ===
1 aa aa2
2 bb bb2
3 cc cc2
The firlst column SeqNo is not the physical column of the table...It may be
a single function to retrieve the sequence number along with the result. I
know there may be a single function in SQL server to retrieve auto
sequence....
Any idea?
Thanks in advance
PeterOoSELECT ID, IDENTITY(INT,1,1) AS seq_number into #temp
FROM TableName
select * FROM #temp
DROP TABLE #temp
Hth
DishanF
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!|||OR
SELECT count(*) RecNum,
a.ID
FROM Agent a join
Agent b
on a.ID >= b.ID
group by a.ID
order by a.ID
DishanF
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!|||Thanks...Can we do another way? This way needs to create a temp table and
I'm wondering if it can affects the performance...
If SQL server has a function like AutoNumber(), there will be nice...
Anyway thanks...And if you have any alternative idea, I'd be appreciated.
"DishanF" wrote:

> SELECT ID, IDENTITY(INT,1,1) AS seq_number into #temp
> FROM TableName
> select * FROM #temp
> DROP TABLE #temp
> Hth
> DishanF
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
>