Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Friday, March 30, 2012

Problem with Check Constraints

I am working with an evaluation copy of SQL Server 2000 for the first
time; my DB experience lies with MS Access.

I have a simple table in SQL Server (tblCompany) that has a field
called "Ticker." When new company stock tickers (i.e., MSFT for
Microsoft) are entered into the field, I'd like them in all
caps--whether the user types msft, Msft, MsFt, etc. In Access, this
was easy--simply set the Format to ">" in table design view.

In SQL Server Design Table view, I've clicked on "Manage Constraints"
and put the following code in that I found elsewhere:

([Ticker] = upper([Ticker]))

I then checked all three boxes below: "Check existing data on
creation," "Enforce constraint for replication," and "Enforce
constraint for INSERTs and UPDATEs." The first one, "Check existing
data..." is checked as I've already entered in some data in the field
in lowercase to see if the check constraint would go back and change
it to Upper Case--this because I'm wanting to ultimately migrate a
table from Access to SQL Server and ensure that all Tickers are in
Upper Case.

I'm able to do this and then save the table design with changes; but
every time, I then go and look at the table data to see if the check
constraint was applied, and each time it is not; then, I go back to
"Manage Constraints" and find that the "Check existing data..." box is
unchecked. I've gone through this SEVERAL times.

Hoping this is something simple. Apologize for my "newbieness." I've
got a "For Dummies" book in front of me as well as numerous Internet
windows open, trying to figure this out. Have checked books online on
the MSFT site as well to no avail.

Thanks in advance--

RADA constraint enforces data integrity rules but does not change existing or
newly inserted data. You need to cleanup your data and then add the
constraint to only permit uppercase values going forward.

If you want to automatically change values to upper case as they are entered
on the server side, you'll need to do this in a trigger. IMHO, this task is
better done in application code and let the database just enforce the data
integrity rule.

I don't know the details of the constraint you are adding but be aware that
case sensitivity is determined by collations in SQL 2000. The default
collation is case insensitive so you'll need to override the default
case-insensitive compare in your constraint. The example script below will
correct existing data and add a check constraint to ensure only upper case
values are allowed.

UPDATE Company
SET Ticker = UPPER('Ticker')
GO

ALTER TABLE Company
ADD CONSTRAINT CK_Ticker
CHECK (Ticker COLLATE SQL_Latin1_General_Cp1_CS_AS = UPPER(Ticker))
GO

On a side note, be aware that Hungarian notation (e.g. 'tbl' prefixes) are
frowned upon in client-server database design. The underlying database
implementation (table or view) should be transparent to database users.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"RAD" <rdavenport@.nyc.rr.com> wrote in message
news:d4119d8.0401251017.28f0b46f@.posting.google.co m...
> I am working with an evaluation copy of SQL Server 2000 for the first
> time; my DB experience lies with MS Access.
> I have a simple table in SQL Server (tblCompany) that has a field
> called "Ticker." When new company stock tickers (i.e., MSFT for
> Microsoft) are entered into the field, I'd like them in all
> caps--whether the user types msft, Msft, MsFt, etc. In Access, this
> was easy--simply set the Format to ">" in table design view.
> In SQL Server Design Table view, I've clicked on "Manage Constraints"
> and put the following code in that I found elsewhere:
> ([Ticker] = upper([Ticker]))
> I then checked all three boxes below: "Check existing data on
> creation," "Enforce constraint for replication," and "Enforce
> constraint for INSERTs and UPDATEs." The first one, "Check existing
> data..." is checked as I've already entered in some data in the field
> in lowercase to see if the check constraint would go back and change
> it to Upper Case--this because I'm wanting to ultimately migrate a
> table from Access to SQL Server and ensure that all Tickers are in
> Upper Case.
> I'm able to do this and then save the table design with changes; but
> every time, I then go and look at the table data to see if the check
> constraint was applied, and each time it is not; then, I go back to
> "Manage Constraints" and find that the "Check existing data..." box is
> unchecked. I've gone through this SEVERAL times.
> Hoping this is something simple. Apologize for my "newbieness." I've
> got a "For Dummies" book in front of me as well as numerous Internet
> windows open, trying to figure this out. Have checked books online on
> the MSFT site as well to no avail.
> Thanks in advance--
> RAD|||On 25 Jan 2004 10:17:18 -0800, rdavenport@.nyc.rr.com (RAD) wrote:

>I am working with an evaluation copy of SQL Server 2000 for the first
>time; my DB experience lies with MS Access.
>I have a simple table in SQL Server (tblCompany) that has a field
>called "Ticker." When new company stock tickers (i.e., MSFT for
>Microsoft) are entered into the field, I'd like them in all
>caps--whether the user types msft, Msft, MsFt, etc. In Access, this
>was easy--simply set the Format to ">" in table design view.
>In SQL Server Design Table view, I've clicked on "Manage Constraints"
>and put the following code in that I found elsewhere:
>([Ticker] = upper([Ticker]))
>I then checked all three boxes below: "Check existing data on
>creation," "Enforce constraint for replication," and "Enforce
>constraint for INSERTs and UPDATEs." The first one, "Check existing
>data..." is checked as I've already entered in some data in the field
>in lowercase to see if the check constraint would go back and change
>it to Upper Case--this because I'm wanting to ultimately migrate a
>table from Access to SQL Server and ensure that all Tickers are in
>Upper Case.
>I'm able to do this and then save the table design with changes; but
>every time, I then go and look at the table data to see if the check
>constraint was applied, and each time it is not; then, I go back to
>"Manage Constraints" and find that the "Check existing data..." box is
>unchecked. I've gone through this SEVERAL times.
>Hoping this is something simple. Apologize for my "newbieness." I've
>got a "For Dummies" book in front of me as well as numerous Internet
>windows open, trying to figure this out. Have checked books online on
>the MSFT site as well to no avail.
>Thanks in advance--
>RAD
That doesn't work, as can be shown with

select ticker from tblCompany where ticker = 'MSFT'

Your row will be returned regardless of the case of the data.

this may be something that can be set at the database level,
alternatively use a trigger to uppercase the data.

Something like;

create trigger instblCompany
on tblCompany
instead of insert
as
insert into tblCompany
select upper(ticker), all other columns
from inserted|||Thanks both Dan and Lyndon--I'll give it a whirl.

RAD

problem with CDO.Message

Hi
we using stroed precedure for sending mail . and we are
using CDOSYS.
It was working fine till yesterday. Suddenly from today its
excuting fine...but no mails has been received by anybody..we tried it
manually. The o/p is "mail send to rajukurian@.gmail.com"
But i dnt receive any mail..Till yrsterday the same procedure was
working fine..
what will be the reason..
Thanks!
RajHi
Have you checked/monitored the SMTP server?
John
"rajukurian@.gmail.com" wrote:
> Hi
> we using stroed precedure for sending mail . and we are
> using CDOSYS.
> It was working fine till yesterday. Suddenly from today its
> excuting fine...but no mails has been received by anybody..we tried it
> manually. The o/p is "mail send to rajukurian@.gmail.com"
> But i dnt receive any mail..Till yrsterday the same procedure was
> working fine..
> what will be the reason..
> Thanks!
> Raj
>|||rajukurian@.gmail.com wrote:
> Hi
> we using stroed precedure for sending mail . and we are
> using CDOSYS.
> It was working fine till yesterday. Suddenly from today its
> excuting fine...but no mails has been received by anybody..we tried it
> manually. The o/p is "mail send to rajukurian@.gmail.com"
> But i dnt receive any mail..Till yrsterday the same procedure was
> working fine..
> what will be the reason..
> Thanks!
> Raj
>
Most likely NOT a SQL Server problem, rather a problem somewhere in the
delivery stream. Check the SMTP server, check your recieving mail
server, check for aggressive spam filtering.
Tracy McKibben
MCDBA
http://www.realsqlguy.com

problem with CDO.Message

Hi
we using stroed precedure for sending mail . and we are
using CDOSYS.
It was working fine till yesterday. Suddenly from today its
excuting fine...but no mails has been received by anybody..we tried it
manually. The o/p is "mail send to rajukurian@.gmail.com"
But i dnt receive any mail..Till yrsterday the same procedure was
working fine..
what will be the reason..
Thanks!
RajHi
Have you checked/monitored the SMTP server?
John
"rajukurian@.gmail.com" wrote:

> Hi
> we using stroed precedure for sending mail . and we are
> using CDOSYS.
> It was working fine till yesterday. Suddenly from today its
> excuting fine...but no mails has been received by anybody..we tried it
> manually. The o/p is "mail send to rajukurian@.gmail.com"
> But i dnt receive any mail..Till yrsterday the same procedure was
> working fine..
> what will be the reason..
> Thanks!
> Raj
>|||rajukurian@.gmail.com wrote:
> Hi
> we using stroed precedure for sending mail . and we are
> using CDOSYS.
> It was working fine till yesterday. Suddenly from today its
> excuting fine...but no mails has been received by anybody..we tried it
> manually. The o/p is "mail send to rajukurian@.gmail.com"
> But i dnt receive any mail..Till yrsterday the same procedure was
> working fine..
> what will be the reason..
> Thanks!
> Raj
>
Most likely NOT a SQL Server problem, rather a problem somewhere in the
delivery stream. Check the SMTP server, check your recieving mail
server, check for aggressive spam filtering.
Tracy McKibben
MCDBA
http://www.realsqlguy.com

Wednesday, March 28, 2012

problem with browsing cube in MSAS 2005

Hi All,

Am working on MSAS 2005 here i installed MSAS 2005 in OS MS 2003 server i did migration from the existing MSAS 2000 Database and Data Sourse to MSAS 2005.Here everything is fine with migration and i can view all the Datasourse,Cubes,Dimensions etc.The problem is when i am doing processing the cube am getting below error please some body help me on this.

OLE DB error: OLE DB or ODBC error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified; IM002.

AS2005 does not support ODBC datasources. To process your cube you should change datasource to use OLEDB provider.


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


Problem with Boolean Nullable parameter in Report Viewer

I have a problem with a nullable boolean parameter.
By default, the value is Null and that's working fine.

The User clicks either true or false, view the report: fine again.

However, from that point on, if the user checks the Null checkbox and
submits the reports, it reverts automatically back to the last True or
False value.

Is this a known problem? Or am I doing something wrong?

Eric

You aren't doing anything wrong. This is a bug. Unfortunately, there is no workaround. If this is causing you signficant problems, please contact customer support directly for a solution.

http://www.microsoft.com/services/microsoftservices/srv_support.mspx

|||

Thanks for the answer.

Is it reasonable to assume that this will get fixed in the next service pack, whenever this is?

|||I can't make any promises at this point (there are many factors involved), but I am pushing for it.|||Thanks

Problem with AuthenticationExtension

Hi,

I got SSRS2005 with FormsAuthentication working for a while now without any problems. I decided to create some kind of 'Account Enabled' functionality and therefore I modified my AuthenticationExtension.cs. But what happened, the new functionality does not work. After adding some logging stuff to this file nothing changed. So it looks as if AuthenticationExtension.css is not being used at all in my security extension. I verified this by removing the file from the project and still...no changes! Other files in my security extension module are being used however. When I make a change to AuthenticationUtilities I can see it in my results.

Does anyone know how this can happen? Why is my extended IAuthenticationExtension not been used?

Thanks,

Hans

I assume you've redeployed the dll to the report server / manager bin directory. Have you tried debugging and stepping into the code?|||...thanks. This brougth me to the solution. I replaced the security dll in my customized application's bin directory but not in the RS-server and RS-manager bin's. After doing this it worked as expected. Obviously only dll's in these bin directories are relevant.|||Hey i have a huge problem, right now my machine has installed SQL 2005 and .NET 2005, but my example for custom security needs SQL 2000.

Could you give the address where you found the FormsSecurity solution, please?
|||Hi, there's in fact no big difference with the extensions you're using with SQL2000. The security extensions should be there when you installed SQL2005. I know that a couple of extra methods came with the Security extension 2005, that you have to override in your own code, but you'll notice soon enough. What error message do you get?sql

Problem with AuthenticationExtension

Hi,

I got SSRS2005 with FormsAuthentication working for a while now without any problems. I decided to create some kind of 'Account Enabled' functionality and therefore I modified my AuthenticationExtension.cs. But what happened, the new functionality does not work. After adding some logging stuff to this file nothing changed. So it looks as if AuthenticationExtension.css is not being used at all in my security extension. I verified this by removing the file from the project and still...no changes! Other files in my security extension module are being used however. When I make a change to AuthenticationUtilities I can see it in my results.

Does anyone know how this can happen? Why is my extended IAuthenticationExtension not been used?

Thanks,

Hans

I assume you've redeployed the dll to the report server / manager bin directory. Have you tried debugging and stepping into the code?|||...thanks. This brougth me to the solution. I replaced the security dll in my customized application's bin directory but not in the RS-server and RS-manager bin's. After doing this it worked as expected. Obviously only dll's in these bin directories are relevant.|||Hey i have a huge problem, right now my machine has installed SQL 2005 and .NET 2005, but my example for custom security needs SQL 2000.

Could you give the address where you found the FormsSecurity solution, please?|||Hi, there's in fact no big difference with the extensions you're using with SQL2000. The security extensions should be there when you installed SQL2005. I know that a couple of extra methods came with the Security extension 2005, that you have to override in your own code, but you'll notice soon enough. What error message do you get?

Problem with AuthenticationExtension

Hi,

I got SSRS2005 with FormsAuthentication working for a while now without any problems. I decided to create some kind of 'Account Enabled' functionality and therefore I modified my AuthenticationExtension.cs. But what happened, the new functionality does not work. After adding some logging stuff to this file nothing changed. So it looks as if AuthenticationExtension.css is not being used at all in my security extension. I verified this by removing the file from the project and still...no changes! Other files in my security extension module are being used however. When I make a change to AuthenticationUtilities I can see it in my results.

Does anyone know how this can happen? Why is my extended IAuthenticationExtension not been used?

Thanks,

Hans

I assume you've redeployed the dll to the report server / manager bin directory. Have you tried debugging and stepping into the code?|||...thanks. This brougth me to the solution. I replaced the security dll in my customized application's bin directory but not in the RS-server and RS-manager bin's. After doing this it worked as expected. Obviously only dll's in these bin directories are relevant.|||Hey i have a huge problem, right now my machine has installed SQL 2005 and .NET 2005, but my example for custom security needs SQL 2000.

Could you give the address where you found the FormsSecurity solution, please?|||Hi, there's in fact no big difference with the extensions you're using with SQL2000. The security extensions should be there when you installed SQL2005. I know that a couple of extra methods came with the Security extension 2005, that you have to override in your own code, but you'll notice soon enough. What error message do you get?

Monday, March 26, 2012

problem with aspnet_ "Could not find stored procedure"


I have developed an asp.net 2.0 web application that uses sql2000 and with storded procedures.
Everything has been working great untill i yesterday found that someone have put in new stored procedures
in the database. The procedures starts with "dbo.aspnet_" like dbo.aspnet_CheckSchemaVersion.
Because i din't create them and i surtenly not call them from the application, i deleted them all.

Now when i try to use my web application nothing works. The app, somehow calls the procedure and becuase they are deleted
an error message is thrown like: Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.

But the strange thing is that the problem only accure when i publish the site on the web server.
if i would publish it to a local folder on my desktop ore just run in debug mode against the database there are no problems.

I don't want to use the aspnet procedures that probebly comes from aspnet_regsql.exe and that im not calling from the code but reacts somehow,
I just want it to tun as it was designed to do.
And if i need them, can someone explain why?

please help :)

Dude, the "aspnet_" stuff is from Microsoft... it's the Membership provider. To get it back run "aspnet_regsql' in c:\windows\microsoft.net\framework\v2.blah (or wherever your windows files are).

|||

Yo Dude :) I did what you said and of course it worked. But i don't know why aspnet_regsql.exe is suddenly needed and all of those procedures that comes along. It worked without it before.

thx :)

sql

Problem with arithmetical calculations

Hello, everyone.

I have some experience working with T-SQL, but now I am faced with problem which I never seen before.

I have query:

SELECT2/(9+1)*1000

This query returns 0, but it must return 200.

I have tried this in SQL 2000 and SQL 2005, but result is the same.

What is wrong?

B.R.

Girts

I have found solution for this problem - it looks very simple and stypid :

SELECT 2/(9*1.0+1)*1000

|||

It's very simple, yes, but stupid? Not at all.

Have you thought about what you're calculating?
How much is 2 divided by 10?
How would one write 0.2 using only integers..? You can't, so it's rounded down to 0.

So your real problem is not how it's calculated, but what datatypes are used to do the calculation. When you add the decimalpoint as you found out, it's no longer done by all integers, but with decimals instead, so the rounding doesn't have to happen.
Thus you get the expected result. =:o)

You can find out more in BOL if you look for 'datatypes' and 'datatype precedence'

=;o)
/Kenneth

|||

Well, this is kind of wierd looking (the bold):

SELECT 2/(9*1.0+1)*1000

But like KeWin is saying it does the trick because it causes the 1.0 to be converted to a numeric value. The same effect can be achieved by:

SELECT 2.0/(9+1)*1000

You really have to be careful to consider the datatype at each step of the evaluation of the equation.

Integer + Integer = Integer
Integer / Integer = Integer

select 1/2 = 0 --because in integer math, you truncate the result, not round
select 1%2 = 1 --% is the mod function, gives you the remainder of the operation
--mod is essential when working with integers

Now consider:

select 1.0 / 1 = 1.000000

Numeric / Integer = Numeric

A trick to use to see the exact type is to use a sql_variant dataype:

declare @.value sql_variant
set @.value = 1.0 / 1

--give precision for integer even though not technically part of datatype
select cast(sql_variant_property(@.value,'baseType') as varchar(10))+
'(' + cast(sql_variant_property(@.value,'precision') as varchar(10))+ ',' +
cast (sql_variant_property(@.value,'scale') as varchar(10)) + ')'

select @.value

Using this query you can see what type is chosen for the output of an expression, either a scalar value, or a mathematic equation.

For the 1.0 / 1 before, this returns:

1.000000

SQL Server chooses a datatype that will always be able to store the result of the equation safely with no loss of precision if possible.

The point is that you have to be really careful with math because one little mess up on a type and your numbers are meaningless:

select (1/2) * 5000.00
select (1.0/2.0) * 5000

the first one is 0, because 1/2 returns integer 0 * numeric 5000.00 = 0.00

the second one 2500.000000, since 1.0/2.0 returns numeric(8,6) 0.500000 * 5000

Hopefully this is a bit clear. Datatype conversion can be tricky. In BOL (for 2005), look up Data Types [SQL Server]; Converting. There is an implicit conversion char to tell you what types will convert to what types as needed.

Problem with Analysis Server

I just installed 2005 and have an Enterprise Editition instance on my local machine. My SSAS service appears to be working properly in Services. However, whenever I try to deploy a cube (simple one from tutorial) or try to connect from Management Console, I get rejected. The error message is:

No connection could be made because the target machine actively refused it (System).

I've tried about everything I can think of and can't get past this. Any guidance would be greatly appreciated.

Rod, can you enable shared memory and try again? This should solve the problem.

Thanks,
Sam Lester (MSFT)

|||How do you "enable" shared memory?sql

Problem with Analysis Server

I just installed 2005 and have an Enterprise Editition instance on my local machine. My SSAS service appears to be working properly in Services. However, whenever I try to deploy a cube (simple one from tutorial) or try to connect from Management Console, I get rejected. The error message is:

No connection could be made because the target machine actively refused it (System).

I've tried about everything I can think of and can't get past this. Any guidance would be greatly appreciated.

Rod, can you enable shared memory and try again? This should solve the problem.

Thanks,
Sam Lester (MSFT)

|||How do you "enable" shared memory?

Problem with Analysis Server

I just installed 2005 and have an Enterprise Editition instance on my local machine. My SSAS service appears to be working properly in Services. However, whenever I try to deploy a cube (simple one from tutorial) or try to connect from Management Console, I get rejected. The error message is:

No connection could be made because the target machine actively refused it (System).

I've tried about everything I can think of and can't get past this. Any guidance would be greatly appreciated.

Rod, can you enable shared memory and try again? This should solve the problem.

Thanks,
Sam Lester (MSFT)

|||How do you "enable" shared memory?

Problem with an aggregation

Hi,

I am new to the reporting services and I've been working on problem in one of my reports all day long and after 8 hours of frusturation I decided ask for a profesional help.

Ok here is my problem: I have a report that calculates the amount of meetings with our clients. The dataset contains an activity_id field that we assign for each our meetings with our clients. SSRS counts these meetings and shows it in a drilldown enabled report. Everything seems fine on the report except that someof the activities involves few different clients and SSRS is not counting the activities multiple times in region drilldown as there is only one activity id associates in that region even though it contains different companies. And I want those companies to be calculated in too.

From the crude drawing below I wanted to explain my dilemma visually. As it can be seen the total number of meetings we had is actually 40. But as we had 3 activities that involves more than 1 clients it only gives 37 as a count. I would like to know is there a way to make the report count the same activity multiple times if activity_id is associated with more than one clients.

I hope I managed to explain my problem

**********************************************************************************************

Manager Region Market Company Meeting Detail

+Manager 1 (9 meetings)

+Manager 2 (37 meetings)

- West (37 meetings)

-Denver (37 meetings)

+Company 1 (5 meetings)

+Company 2 (2meetings)

+Company 3 (2meetings)

+Company 4 (3meetings)

+Company 5 (0meetings)

+Company 6 (0meetings)

+Company 7 (5meetings)

+Company 8 (1meetings)

+Comapny 9 (19meetings)

+Company 10 (3meetings)

Total (40 meetings)

You would need to use a composite key by grouping on the combination of the activity_id and company_id rather than just the activity_id. I believe strongly in doing as much of the math as possible in the SQL statement, rather than the report. That way you can use your same report and simply show the total that was calculated rather than the calculating the total. For example:

Code Snippet

SELECT

base.Manager,

base.Region,

base.Market,

base.Company,

base.MeetingDetail,

MTot.Total as ManagerTotal,

RTot.Total as RegionTotal,

M2Tot.Total as MarketTotal,

CTot.Total as CompanyTotal

FROM

baseTable base,

(SELECT COUNT(*) AS Total FROM baseTable bt WHERE bt.Manager = base.Manager) MTot,

(SELECT COUNT(*) AS Total FROM baseTable bt WHERE bt.Manager = base.Manager AND bt.Region = base.Region) RTot,

etc.

This is really bad SQL, but I don't know the actual structure that you are working from and I think this conveys the idea.

If this isn't clear, post or send me the table structures and I will help you build a query that calculates your totals.

Larry

|||

Thank you Larry,

I will try to follow up with your suggestion hopefully it will help. if I got stuck I will post the table structure to you. Thank you again for your prompt response.

Regards,

Burak

|||

Hi Larry,

I've been trying to use your suggestion but I couldn't figure it out a way to use it.

My sql code is as follows

Code Snippet

SELECT DISTINCT
TOP 100 PERCENT ACTIVITY_ID, Date, ACTIVITY_TYP_NM, LAST_NM, FIRST_NM, COMPANY_NM, DISPLAY_NM, Region, SUMMARY, MLAE, Market,
STATE, Expr1
FROM dbo.INTV_Sales_Funnel
GROUP BY ACTIVITY_ID, Date, ACTIVITY_TYP_NM, LAST_NM, FIRST_NM, COMPANY_NM, DISPLAY_NM, Region, SUMMARY, MLAE, Market, STATE,
Expr1
ORDER BY ACTIVITY_ID, Date, SUMMARY, COMPANY_NM

MLAE represents the Manager

and Expr1 represents the Count

the thing is when I used the count im getting a value that more than I should get and the reason for this, is in some of our events we invite multiple people from a company or multiple people from multiple companies.But the report should reflect only 1 count of the event if the meeting had either 1 person or more from a single company. I managed to get rid of those extra people on the meetings over the report so activities only listed once. But it seems like I really need to find a way to make that calculation over the report. Is there a way to use Count Distinct on report with 2 values. Right now I am using Activity ID but I guess if add both activity id and company name as you mentioned earlier on your response I might be able to solve this problem.

|||

First, on re-reading your original post, I am not sure that your original solution wasn't correct. If you had 37 meetings and 3 meetings had two customers each then you would show the result of the sum of the meetings that each customer attended was 40 rather than 37 because each of the three meetings with two customers each would be counted twice.

That said, here is a method of generating the query that will return your results. Lets start with what you know that you want and build the query from left to right on your table above. This will not get us the most optimized query, but it should show the method of layering results within a query that can allow you to get complex results with simple nested queries. One advantage to this method is that you can check the results at each stage.

First, let's get a count of all of the meetings for the managers:

Code Snippet

SELECT
DISF.MLAE,
COUNT(DISF.Activity_Id) ManagerTotal
FROM
(SELECT
DISTINCT
MLAE,
Activity_Id
FROM
INTV_Sales_Funnel
) DISF
GROUP BY
DISF.MLAE


Then, let's get the count of meetings per region per manager:

Code Snippet

SELECT
DISF.MLAE,
DISF.Region,
COUNT(DISF.Activity_Id) RegionTotal
FROM
(SELECT
DISTINCT
MLAE,
Region,
Activity_Id
FROM
INTV_Sales_Funnel
) DISF
GROUP BY
DISF.MLAE,
DISF.Region

Next, let's get the count of meetings per market within a region for each manager:

Code Snippet

SELECT
DISF.MLAE,
DISF.Region,
DISF.Market,
COUNT(DISF.Activity_Id) MarketTotal
FROM
(SELECT
DISTINCT
MLAE,
Region,
Market,
Activity_Id
FROM
INTV_Sales_Funnel
) DISF
GROUP BY
DISF.MLAE,
DISF.Region,
DISF.Market

Lastly, let's get the count of meetings per customer within each market and region for each manager:

Code Snippet

SELECT
DISF.MLAE,
DISF.Region,
DISF.Market,
DISF.Company_NM,
COUNT(DISF.Activity_Id) CompanyTotal
FROM
(SELECT
DISTINCT
MLAE,
Region,
Market,
Company_NM,
Activity_Id
FROM
INTV_Sales_Funnel
) DISF
GROUP BY
DISF.MLAE,
DISF.Region,
DISF.Market,
DISF.Company_NM

Then, when you want to combine them and return all of the values, join each of the four queries to the main query as follows:

Code Snippet

SELECT
main.Activity_Id,
main.Date,
main.ACTIVITY_TYP_NM,
main.LAST_NM,
main.FIRST_NM,
main.COMPANY_NM,
main.DISPLAY_NM,
main.Region,
main.SUMMARY,
main.MLAE,
main.Market,
main.STATE,
mgr.ManagerTotal,
rgn.RegionTotal,
mkt.MarketTotal,
cmp.CompanyTotal
FROM
INTV_Sales_Funnel main
JOIN
(
SELECT
DISF.MLAE,
COUNT(DISF.Activity_Id) ManagerTotal
FROM
(SELECT
DISTINCT
MLAE,
Activity_Id
FROM
INTV_Sales_Funnel
) DISF
GROUP BY
DISF.MLAE
) mgr
ON
main.MLAE = mgr.MLAE
JOIN
(
SELECT
DISF.MLAE,
DISF.Region,
COUNT(DISF.Activity_Id) RegionTotal
FROM
(SELECT
DISTINCT
MLAE,
Region,
Activity_Id
FROM
INTV_Sales_Funnel
) DISF
GROUP BY
DISF.MLAE,
DISF.Region
) rgn
ON
main.MLAE = rgn.MLAE
AND
main.Region = rgn.Region
etc.

I hope this helps. Please let me know how it turns out.

Larry

Friday, March 23, 2012

Problem with Agent on 2000 server - jobs hanging

I have a server that had SQL agent working on it, and running scheduled
jobs on set interval forever. Windows Server 2003, SQL 2000, most
current service packs on both.
I installed an instance of SQL 2005 on this server.
Now, when I look at Enterprise Manager & try to see what's happening
with the jobs, I see that the jobs are sitting out there & will kick off
when they are supposed to run, or I can kick them off manually.
However, now, they will run to certain steps in a job, and it will just
"hang". The jobs that hang are the ones that are running DTS jobs:
DTSRun /~Z0xC9C........
These particular jobs haven't been changed in months, and were running
fine until the install of SQL 2005 on this server.
Any idea what's happening or how to fix it?
It may be a locking. You can really easy to detect in Current Activity
window, processes view, last two fields if you scroll to the right, 'blocked
by" and "blocking" columns.
"Blasting Cap" wrote:

> I have a server that had SQL agent working on it, and running scheduled
> jobs on set interval forever. Windows Server 2003, SQL 2000, most
> current service packs on both.
> I installed an instance of SQL 2005 on this server.
> Now, when I look at Enterprise Manager & try to see what's happening
> with the jobs, I see that the jobs are sitting out there & will kick off
> when they are supposed to run, or I can kick them off manually.
> However, now, they will run to certain steps in a job, and it will just
> "hang". The jobs that hang are the ones that are running DTS jobs:
> DTSRun /~Z0xC9C........
>
> These particular jobs haven't been changed in months, and were running
> fine until the install of SQL 2005 on this server.
> Any idea what's happening or how to fix it?
>
sql

Problem with Agent on 2000 server - jobs hanging

I have a server that had SQL agent working on it, and running scheduled
jobs on set interval forever. Windows Server 2003, SQL 2000, most
current service packs on both.
I installed an instance of SQL 2005 on this server.
Now, when I look at Enterprise Manager & try to see what's happening
with the jobs, I see that the jobs are sitting out there & will kick off
when they are supposed to run, or I can kick them off manually.
However, now, they will run to certain steps in a job, and it will just
"hang". The jobs that hang are the ones that are running DTS jobs:
DTSRun /~Z0xC9C........
These particular jobs haven't been changed in months, and were running
fine until the install of SQL 2005 on this server.
Any idea what's happening or how to fix it?It may be a locking. You can really easy to detect in Current Activity
window, processes view, last two fields if you scroll to the right, 'blocked
by" and "blocking" columns.
"Blasting Cap" wrote:
> I have a server that had SQL agent working on it, and running scheduled
> jobs on set interval forever. Windows Server 2003, SQL 2000, most
> current service packs on both.
> I installed an instance of SQL 2005 on this server.
> Now, when I look at Enterprise Manager & try to see what's happening
> with the jobs, I see that the jobs are sitting out there & will kick off
> when they are supposed to run, or I can kick them off manually.
> However, now, they will run to certain steps in a job, and it will just
> "hang". The jobs that hang are the ones that are running DTS jobs:
> DTSRun /~Z0xC9C........
>
> These particular jobs haven't been changed in months, and were running
> fine until the install of SQL 2005 on this server.
> Any idea what's happening or how to fix it?
>

Problem with Agent on 2000 server - jobs hanging

I have a server that had SQL agent working on it, and running scheduled
jobs on set interval forever. Windows Server 2003, SQL 2000, most
current service packs on both.
I installed an instance of SQL 2005 on this server.
Now, when I look at Enterprise Manager & try to see what's happening
with the jobs, I see that the jobs are sitting out there & will kick off
when they are supposed to run, or I can kick them off manually.
However, now, they will run to certain steps in a job, and it will just
"hang". The jobs that hang are the ones that are running DTS jobs:
DTSRun /~Z0xC9C........
These particular jobs haven't been changed in months, and were running
fine until the install of SQL 2005 on this server.
Any idea what's happening or how to fix it?It may be a locking. You can really easy to detect in Current Activity
window, processes view, last two fields if you scroll to the right, 'blocked
by" and "blocking" columns.
"Blasting Cap" wrote:

> I have a server that had SQL agent working on it, and running scheduled
> jobs on set interval forever. Windows Server 2003, SQL 2000, most
> current service packs on both.
> I installed an instance of SQL 2005 on this server.
> Now, when I look at Enterprise Manager & try to see what's happening
> with the jobs, I see that the jobs are sitting out there & will kick off
> when they are supposed to run, or I can kick them off manually.
> However, now, they will run to certain steps in a job, and it will just
> "hang". The jobs that hang are the ones that are running DTS jobs:
> DTSRun /~Z0xC9C........
>
> These particular jobs haven't been changed in months, and were running
> fine until the install of SQL 2005 on this server.
> Any idea what's happening or how to fix it?
>

Problem With a Very Big Tables in SQL Server 2000

Hi, every one
I have a big big problem in SQL Sever 2000 working with a very very big problem

This is My Story
-
I have a very big table (36,000,000 row and every day we add 400,000 new row) and i have a page ASP Classic that run Stored Procedural in Database that make ajoins betwen that table and other small tables (100,000 roww),
in this page i display some summery information that back from this Stored Procedural.
The problem is runung any query on this Stored Procedural Take from 1 hour to 3
how can i optmaize this table ? to make query run faster

We can certainly help if we know the schema of the tables involved and the join conditions. Please post DDL and the script to help you.

|||

Hi,

To optimize this table try the following:

-Reduce Number of Columns

Try to reduce the number of columns in a table. The fewer the number of columns in a table, the less space the table will use, since more rows will fit on a single data page, and less I/O overhead will be required to access the table's data.

-Avoid Un-necessary Indexes

Avoid creating un-necessary indexes on table thinking they would improve your performance. Only join tables that you need

-TEXT datatype

Unless you are using it for really large data. The TEXT datatype is not flexible to query, is slow and wastes a lot of space if used incorrectly. Sometimes a VARCHAR will handle your data better.

-Avoid NULLable columns

When possible, normalize your table and separate your nullable columns. They consume an extra byte on each NULLable column in each row and have more overhead associated when querying data.

Regards,

Tarek Ghazali

SQL Server MVP

http://www.sqlmvp.com

|||

The number 1 way to improve performance where you only need summary information out of a query is to maintain summaries.

Also, if you are only gathering summary information from recent times you can partition the table.

A tried and proven design approach to systems is to not perform redundant work.

If you are summarising the same detailed data many times to present it on a page you are doing redundant work.

Best Regards

Peter

|||

table is very big and have about 40 columns

what about index or clustered index or partioning

|||

Sorry to bring the bad news, but this problem can't be solved by simply putting this on a forum. Far to many variables are in play here. If I look at your problem I think your queries are using a table scan to gather the summary info (assumption 1). I presume you don't need all columns in the summary, so avoiding a table scan would be a possibility (assumption 2). If both assumptions are right, a covering index might (assumption 3) be a solution to your problem.

Another solution would be an extra column with the summary data (allready mentioned). Update this data by triggers so you only have to do a select and no more calculations. Yet an other solution could be an indexed view with the calculation included.

I'm not sure if this helped, but this is not so easy answered. The answer depends on the table structure, the query you're running, the data involved and even your hardware. If you supply the table structure, the query and the query plans, maybe we could say something usefull.

|||

In order to verify your indexes, or to determine if additional indexing will help, you may wish to explore using the 'Database Tuning Advisor'.

In general, those are not extraordinarily large tables for SQL Server. With tables containing over a billion rows, I still expect sub-second response to typical queries -even JOINs. It is a matter of anticipating the queries, creating summary tables if need be, proper indexing, and adequate hardware.

Reporting queries are a different 'animal', and may require very different data handling -even specialized servers.

|||

I will do the following

1- do cluster unique index

2- try to minimize # of columns to what i need only

3-try to create temp table that will hold summerized data

Problem With a Very Big Tables in SQL Server 2000

Hi, every one
I have a big big problem in SQL Sever 2000 working with a very very big problem

This is My Story
------
I have a very big table (36,000,000 row and every day we add 400,000 new row) and i have a page ASP Classic that run Stored Procedural in Database that make ajoins betwen that table and other small tables (100,000 roww),
in this page i display some summery information that back from this Stored Procedural.
The problem is runung any query on this Stored Procedural Take from 1 hour to 3
how can i optmaize this table ? to make query run faster :eek:Hi

Please can you post the relevent DML and DDL? Please see the sticky at the top of the forum for mor info.|||Sounds like the tables aren't indexed properly...

Read the hint link at the top of the forum, or read this

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

And post what the instructions tell you to post|||sorry, it`s my first time

but what DML or DDL i have to post|||sorry, it`s my first time

but what DML or DDL i have to post

DML = Data Manipulation Language (SELECT, INSERT, UPDATE, DELETE statements)

DDL = Data Definition Language (CREATE <object>, DROP <object>, etc)

Regards,

hmscott|||i know waht DML & DDL mean but in my case it`s not imortant|||i can`t use index because i have to insert about 6000 row every 10min
and index will slow it down|||i can`t use index because i have to insert about 6000 row every 10min
and index will slow it down WTF? So you are willing to sacrifice your application/business logic query for the sake of speedy inserts? I would put forth the thought that if your inserts are speedy as hell, it really doesn't matter if you can't access the data once it has been inserted.

In any case, this thread smells like another of our favorite types. You know, the "I know what you are telling me to do is correct, but I can't do it. Can you wave your magic wands instead?" kind of thread.

And yes, in your case the DDL and DML are certainly important.

Well, unless you are shooting for a "I know what you are telling me to do is correct, but I can't do it. Can you wave your magic wands instead?, and BTW, I am not going to tell you anything about my database, so you will need your magic x-ray glasses as well" thread.|||I know what you are telling me to do is correct, but I can't do it. Can you wave your magic wands instead?

that's called hardware. lots of it of the expensive nature. who needs efficient design and coding when you can just buy a bigger box?;)|||i can`t use index because i have to insert about 6000 row every 10min
and index will slow it down

Do tell. Have you quantified how much the slowdown is?|||that's called hardware. lots of it of the expensive nature. who needs efficient design and coding when you can just buy a bigger box?;)

We have one of those right now. The vendor wants a dedicated 8-way server running SQL 2005 to support 1,000 concurrent users and a 17 GB database.

The vendor insists that this is the only way to achieve 1,000 concurrent users and that this is "standard practice" (a dedicated database server).

:rolleyes:

Regards,

hmscott|||i can`t use index because i have to insert about 6000 row every 10min
and index will slow it down

you funny

You have an architechture problem

Do the inserts into a stage table, then have a separate process (job) that inserts the rows from stage every x minutes or so

You need an index, or you happy with mutli-hour queries?

Tell you what, I'm leaving for the weekend, and you put a big simle on my face

Thanks|||Oh, and lets see

6,000 rows every 10 minutes...which is
600 row every minute...which is
10 rows a second

And you think that's a lot?

I doubt sql server would even blink|||i can`t use index because i have to insert about 6000 row every 10min
and index will slow it downIf you don't have indexes then you have a heap. You can get better insert performance with an appropriate clustered index than a heap.

how can i optmaize this table ?
......
i know waht DML & DDL mean but in my case it`s not imortant
What you are saying is that you have a query that acts on a table and it runs like a dog. But the query and the table are irrelevent? If you go to a mechanic and tell him your car is not running properly and he asks to look under the bonnet (hood if you are American) do you think that it is irrelevant?

Another question - how many rows do you return to the ASP page?|||number of row depend on the user selection filters
i have number of dropdown list that the user will select from them,
ex: i have the date(From - to) if the user select the range 1 day it will return about 40 row, if more it more|||any idea to solve this problem|||I would suggest, as a start, that you please post the relevent DML and DDL? (Please see the sticky at the top of the forum for more info.).

Also, Sounds like the tables aren't indexed properly...

Read the hint link at the top of the forum, or read this

http://weblogs.sqlteam.com/brettk/ar...5/25/5276.aspx

And post what the instructions tell you to post.

Then we can look and take a stab at assisting you with a wave of the wand, as necessary.|||and this is my table

CREATE TABLE [dbo].[tblVoIPCDRs](
[cdrId] [decimal](19, 0) NOT NULL,
[cdrNativeID] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[cdrAccountCode] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrUserId] [int] NOT NULL,
[cdrUserName] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrSrcNum] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrDstNum] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrDstField] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrDContext] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrSrcChannel] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrDstChannel] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrCallDate] [datetime] NULL,
[cdrDuration] [decimal](18, 0) NOT NULL,
[cdrBillSec] [int] NOT NULL,
[cdrDisposition] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[vtrId] [int] NOT NULL,
[vrUserId] [int] NOT NULL,
[vrUserName] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[vdsId] [int] NOT NULL,
[vcsId] [int] NOT NULL,
[cdrCallGK] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraCallID] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraConfID] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraConnectTime] [datetime] NULL,
[meraDestinationFaststart] [smallint] NULL,
[meraDestinationTunnelling] [smallint] NULL,
[meraDialPeerName] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDisconnectCodeLocal] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDisconnectCodeQ931] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDisconnectTime] [datetime] NULL,
[meraDstBytesIn] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstBytesOut] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstCodec] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstIP] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstName] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstNumberBill] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstNumberIn] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstNumberOut] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstRTPIP] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraDstUser] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraElapsedTime] [decimal](18, 0) NULL,
[meraHost] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraInitialIncomingLocalAddress] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraLARFaultReason] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraOutgoingLocalAddress] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraPDDReason] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraPDDTime] [decimal](18, 0) NULL,
[meraProxyMode] [int] NULL,
[meraQoS] [int] NULL,
[meraRadiusUser] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraRecordID] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraRemoteGatekeeperIP] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraRouteRetries] [smallint] NULL,
[meraSCDTime] [decimal](18, 0) NULL,
[meraSelectedIncomingLocalAddress] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSetupTime] [datetime] NULL,
[meraSourceFaststart] [smallint] NULL,
[meraSourceTunnelling] [smallint] NULL,
[meraSrcBytesIn] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcBytesOut] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcCodec] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcIP] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcName] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcNumberBill] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcNumberIn] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcNumberOut] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcRTPIP] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[meraSrcUser] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdrActive] [smallint] NOT NULL,
[cdrInvoicedCustomer] [smallint] NOT NULL,
[cdrPaidVendor] [smallint] NOT NULL
) ON [PRIMARY]|||my stored procedral is to big i will post it into 2 parts
part 1

ALTER proc [dbo].[spVoIPCalldetailMeraPartitioned]
@.userId int=null, -- filter: user id. overrides custid when supplied
@.custId int=null, -- filter: customer id
@.vcsId int=null, -- filter: status
@.vdsId int=null, -- filter: destination id
@.beginDt datetime=null, -- filter: begin date of call
@.endDt datetime=null, -- filter: end date of call
@.srchFor nvarchar(100)=null, -- filter: searches all result fields for given text
@.sortBy varchar(200)=null, -- order by comma-seperated sort fields
@.qryMode int=1, -- 0=details 1=grandtotal 2=accountcode 3=DialCode 4:carrier 5=Country+Breakout 6=callmonth 7=calldate 8=dayofweek 9=hour 10=vendor 11=Country 12=Country & Mobile Carrier
@.detailMode int=null, -- one of above qryMode values for which detail is requested
@.detailFilter nvarchar(500)=null, -- grouping filter for detail view
@.vendor varchar(10)=null, -- grouping filter for detail view
@.vendorUserId varchar(10)=null, -- grouping filter for detail view
@.systemid varchar(3)=null -- grouping filter for detail view
as

-- set local variables
declare @.q varchar(4200) -- query
declare @.f varchar(3100) -- filter
declare @.s varchar(250) -- search string
declare @.c nvarchar(2) set @.c=char(13) -- carriage return
declare @.b nvarchar(25) -- begin date
declare @.e nvarchar(25) -- end date

declare @.dd nvarchar(100) set @.dd='Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
declare @.mm nvarchar(100) set @.mm='January February March April May June July August September October November December'

declare @.t nvarchar(900) -- filter name for summary
declare @.g nvarchar(600) -- group name for summary
declare @.g1 nvarchar(15) set @.g1='''All Calls'''
declare @.g2 nvarchar(25) set @.g2='cdr.cdrAccountCode'
declare @.g3 nvarchar(200) set @.g3='isNull(cdr.vdsName + isnull('' - ''+cdr.vdsType,'''') + isnull('' - ''+cdr.vdsMobileCarrier,'''') + isnull('' - ''+cdr.vdsDescription,'''') + '' - '' + cdr.vdsDialcode, ''Unknown - System Default'')'
declare @.g4 nvarchar(55) set @.g4='isnull(cdr.vdsDescription,''Unknown'')'
declare @.g5 nvarchar(200) set @.g5=' isNull(cdr.vdsName + isnull('' - ''+cdr.vdsType,'''') + isnull('' - ''+cdr.vdsMobileCarrier,'''') + isnull('' - ''+cdr.vdsDescription,''''), ''Unknown - System Default'') '
declare @.g6 nvarchar(95) set @.g6=' mm.value + '', '' + right(year(cdr.cdrCallDate),4)'
declare @.g7 nvarchar(250) set @.g7=' ltrim(year(cdr.cdrCallDate))+right(''0''+ltrim(day (mm.idx+1)),2)+right(''0''+ltrim(day(cdr.cdrCallDa te)),2)+'' - '' + mm.value + '' '' + right(''0''+ltrim(day(cdr.cdrCallDate)),2) + '', '' + ltrim(year(cdr.cdrCallDate)) '
declare @.g8 nvarchar(85) set @.g8=' ltrim(dd.idx+1)+'' - ''+dd.value '
declare @.g9 nvarchar(250) set @.g9=' CONVERT(datetime, (CONVERT(varchar, datepart(mm,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(dd,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(yyyy,cdr.cdrCallDate)))) , datepart(hh,cdr.cdrCallDate) '
declare @.g10 nvarchar(350) set @.g10=' ISNULL(gateways.[description], ISNULL(cdr.vrUserName, ''Unknown - System Default'' )) '
declare @.g11 nvarchar(200) set @.g11='isNull(cdr.vdsName + isnull('' - ''+cdr.vdsType,''''), ''Unknown - System Default'') '
declare @.g12 nvarchar(200) set @.g12='isNull(cdr.vdsName + isnull('' - ''+cdr.vdsType,'''') + isnull('' - ''+cdr.vdsMobileCarrier,''''), ''Unknown - System Default'') '

print @.systemid
print @.sortBy
-- fix qryMode & detailMode
if @.qryMode<0 or @.qryMode>12 set @.qryMode=1
if @.detailMode<0 or @.detailMode>12 set @.detailMode=null

-- fix requested IDs
if @.userId>0 set @.custId=null if @.custId>0 set @.userId=null

-- fix requested dates
if len(@.beginDt)>0 or len(@.endDt)>0
begin
set @.beginDt=isnull(@.beginDt,'jan 01, 2000') set @.endDt=isnull(@.endDt,getdate()+1)
if @.beginDt>@.endDt set @.endDt=@.beginDt
set @.b=cast(month(@.beginDt) as varchar)+'/'+cast(day(@.beginDt) as varchar)+'/'+cast(year(@.beginDt) as varchar)+' '+cast(datepart(hh,@.beginDt) as varchar)+':'+cast(datepart(n,@.beginDt) as varchar)+':00.01'
set @.e=cast(month(@.endDt) as varchar)+'/'+cast(day(@.endDt) as varchar)+'/'+cast(year(@.endDt) as varchar)+' '+cast(datepart(hh,@.endDt) as varchar)+':'+cast(datepart(n,@.endDt) as varchar)+':59.59'

-- construct date filter
set @.f='where cdr.cdrCallDate between '''+@.b+''' and '''+@.e+''' '+@.c
end

-- fix requested search strings
set @.s=replace(replace(replace(ltrim(rtrim(@.srchFor)), '''','''),'_','[_]'),'%','[%]')
if len(@.detailFilter)>0 set @.detailFilter=replace(replace(replace(ltrim(rtrim( @.detailFilter)),'''','''),'_','_'),'%','[%]')

-- assign data grouping based on request mode
if @.qryMode=0
begin
if @.detailMode=1 begin set @.t=@.g1 end
else if @.detailMode=2 begin set @.t=@.g2 end
else if @.detailMode=3 begin set @.t=@.g3 end
else if @.detailMode=4 begin set @.t=@.g4 end
else if @.detailMode=5 begin set @.t=@.g5 end
else if @.detailMode=6 begin set @.t=@.g6 end
else if @.detailMode=7 begin set @.t=@.g7 end
else if @.detailMode=8 begin set @.t=@.g8 end
else if @.detailMode=9 begin set @.t= ' CONVERT(datetime, (CONVERT(varchar, datepart(mm,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(dd,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(yyyy,cdr.cdrCallDate))) + '' '' + convert(varchar,datepart(hh,cdr.cdrCallDate)) + '':00'') >= convert(datetime, '''+@.detailFilter+''' + '':00'') AND CONVERT(datetime, (CONVERT(varchar, datepart(mm,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(dd,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(yyyy,cdr.cdrCallDate))) + '' '' + convert(varchar,datepart(hh,cdr.cdrCallDate)) + '':00'') <= convert(datetime, '''+@.detailFilter+''' + '':59:59'') ' end
else if @.detailMode=10 begin set @.t=@.g10 end
else if @.detailMode=11 begin set @.t=@.g11 end
else if @.detailMode=12 begin set @.t=@.g12 end

end
else if @.qryMode=1 begin set @.g=@.g1 end
else if @.qryMode=2 begin set @.g=@.g2 end
else if @.qryMode=3 begin set @.g=@.g3 end
else if @.qryMode=4 begin set @.g=@.g4 end
else if @.qryMode=5 begin set @.g=@.g5 end
else if @.qryMode=6 begin set @.g=@.g6 end
else if @.qryMode=7 begin set @.g=@.g7 end
else if @.qryMode=8 begin set @.g=@.g8 end
else if @.qryMode=9 begin set @.g=@.g9 end
else if @.qryMode=10 begin set @.g=@.g10 end
else if @.qryMode=11 begin set @.g=@.g11 end
else if @.qryMode=12 begin set @.g=@.g12 end
-- construct search filter
if len(@.s)>0
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
set @.f=@.f +' (cdr.userFN like ''%'+@.s+'%'' or cdr.userLN like ''%'+@.s+'%'' or cdr.userUnixName like ''%'+@.s+'%'' '+@.c
set @.f=@.f +' or cdr.cdrSrcNum like ''%'+@.s+'%'' or cdr.cdrSrcChannel like ''%'+@.s+'%'' or cdr.cdrDstNum like ''%'+@.s+'%'' '+@.c
set @.f=@.f +' or ''1007'' like ''%'+@.s+'%'' or cdr.vdsName like ''%'+@.s+'%'' or cdr.vcsName like ''%'+@.s+'%'' )'+@.c
end|||this is part 2

-- construct detail filter
if @.qryMode=0 and @.detailMode>0 and @.detailMode<=12 and len(@.detailFilter)>0
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
if @.detailMode=3 set @.f=@.f +'cdr.vdsId = '''+@.detailFilter+''' ' +@.c
else set @.f=@.f +@.t +' = '''+@.detailFilter+''' ' +@.c
end
else if @.qryMode=0 and @.detailMode=9 and len(@.detailFilter)>0
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
if @.detailMode=3 set @.f=@.f +'cdr.vdsId = '''+@.detailFilter+''' ' +@.c
else set @.f=@.f +@.t +@.c
end

-- get fields from calls table
set @.q='select '+@.c
if @.qryMode=0 -- detail mode
begin
set @.q=@.q +'cdr.custId, cdr.userId, cdr.userUnixName, cdr.userUnixName AS callSummaryName, cdr.userFN+'' ''+left(cdr.userLN,1)+''.'' userShortname, '+@.c
set @.q=@.q +'cdr.cdrCallDate AS vcdStartDt, cdr.cdrSrcNum, cdr.cdrSrcChannel, cdr.cdrAccountCode, cdr.cdrDstChannel, ''1007'' As vcdDstPrefix, cdr.cdrDstNum, isNull(cdr.vdsName + isnull('' - ''+cdr.vdsType,'''') + isnull('' - ''+cdr.vdsMobileCarrier,'''') + isnull('' - ''+cdr.vdsDescription,'''') , ''Unknown - System Default'') AS vdsName, cdr.cdrCallGK, cdr.vrUserName, '+@.c
set @.q=@.q + ' (CONVERT(varchar, datepart(mm,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(dd,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(yyyy,cdr.cdrCallDate))) AS CallDate, '
set @.q=@.q +'cdr.vcsName, cdr.vcsColor, '+@.c
set @.q=@.q +' cdr.dcqId, cdr.dcqDescription, cdr.dcqNote, '+@.c
set @.q=@.q +'cdr.cdrBillSec, ''0'' AS callRate, ''0'' AS callAdjRate, ''0'' AS callCost, cdr.vdsId AS vdsId, cdr.meraRouteRetries, cdr.meraPDDTime '+@.c
end -- summary modes: add specific output fields
else if @.qryMode=3 begin set @.q=@.q +' cdr.vdsId, ' end
if @.qryMode>0 -- summary modes: add counts
begin
set @.q=@.q + @.g +' callSummaryName, '+@.c
set @.q=@.q +'min(cdr.cdrCallDate) callMinDt, '+@.c
set @.q=@.q +'max(cdr.cdrCallDate) callMaxDt, '+@.c
set @.q=@.q +'count(*) callTotalCount, '+@.c
set @.q=@.q + ' min((CONVERT(varchar, datepart(mm,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(dd,cdr.cdrCallDate)) + ''/'' + CONVERT(varchar, datepart(yyyy,cdr.cdrCallDate)))) AS CallDate, '
set @.q=@.q +'isnull(sum(case cdr.vcsId when 2 then 1 else 0 end),0) callTotalAnswered, '+@.c
set @.q=@.q +'isnull(sum(case cdr.vcsId when 2 then 1 else 0 end),0)*100/(case count(*) when 0 then 1 else count(*) end) callTotalASR, '+@.c
set @.q=@.q +'isnull(sum(cdr.cdrBillSec),0)/(case isnull(sum(case cdr.vcsId when 2 then 1 else 0 end),0) when 0 then 1 else isnull(sum(case cdr.vcsId when 2 then 1 else 0 end),0) end) callTotalACD, '+@.c
set @.q=@.q +'isnull(sum(cdrBillSec),0) callTotalSec, '+@.c
set @.q=@.q +' AVG(CAST(IsNull(cdr1.NumberOfRetries, 0) AS Numeric)) averageRouteRetries, '+@.c
set @.q=@.q +' AVG(IsNull(cdr.meraPDDTime, 0)) averagePDD, '+@.c
set @.q=@.q + ' isnull(sum(CASE WHEN (cdr.cdrBillSec = 0) THEN (0) WHEN isnull(cdr.cdrBillSec,0) <= (6) THEN (6) ELSE ((( CASE WHEN (isnull(cdr.cdrBillSec,0)%(6))=0 then (isnull(cdr.cdrBillSec,0)%(6)) Else 6-(isnull(cdr.cdrBillSec,0)%(6)) End))+(isnull(cdr.cdrBillSec, 0)))END),0) callTotalFinal, ' + @.c
set @.q=@.q + ' isnull(sum(CASE WHEN (cdr.cdrBillSec = 0) THEN (0) WHEN isnull(cdr.cdrBillSec,0) <= (30) THEN (30) ELSE ((( CASE WHEN (isnull(cdr.cdrBillSec,0)%(6))=0 then (isnull(cdr.cdrBillSec,0)%(6)) Else 6-(isnull(cdr.cdrBillSec,0)%(6)) End ))+(isnull(cdr.cdrBillSec,0)))END),0) callTotalFinal2,' + @.c
set @.q=@.q + ' isnull(sum(CASE WHEN (cdr.cdrBillSec = 0) THEN (0) WHEN isnull(cdr.cdrBillSec,0) <= (30) THEN (30) ELSE isnull(cdr.cdrBillSec,0) END),0) callTotalFinal3, ' + @.c
set @.q=@.q + ' isnull(sum(CASE WHEN (cdr.cdrBillSec = 0) THEN (0) WHEN isnull(cdr.cdrBillSec,0) <= (60) THEN (60) ELSE ((( CASE WHEN (isnull(cdr.cdrBillSec,0)%(60))=0 then (isnull(cdr.cdrBillSec,0)%(60)) Else 60-(isnull(cdr.cdrBillSec,0)%(60)) End))+(isnull(cdr.cdrBillSec, 0)))END),0) callTotalFinal4, ' + @.c
set @.q=@.q +' 0 AS callTotalCost , MAX(cdr.vdsId) AS vdsId, '+@.c
set @.q=@.q + ' SUM(case meraDisconnectCodeQ931 when 16 then
1 else 0 end) AS NCC,
SUM(case meraDisconnectCodeQ931 when 1 then
1
when 28 then
1 else 0 end) AS WN,
SUM(case meraDisconnectCodeQ931
when 34 then
1
when 17 then
1 else 0 end) AS Busy,
SUM(case
when (meraDisconnectCodeQ931<>1) AND (meraDisconnectCodeQ931<>28) AND (meraDisconnectCodeQ931<>34) AND (meraDisconnectCodeQ931<>17) AND (meraDisconnectCodeQ931<>16) then
1 else 0 end) AS Other '
end

-- get cdr table
If @.qryMode=0
begin
set @.q=@.q +' from tblVoIPCDRTemp cdr WITH (NOLOCK) left join tblUser uu on (cdr.vrUserName=uu.userUnixName) left JOIN tblCustomer cc on (uu.CustId = cc.CustId) ' + @.c
end
Else
begin
set @.q=@.q +' from (Select MAX(cddr.cdrNativeId) AS cdrNativeId, count(*) AS NumberOfRetries from tblVoIPCDRs cddr where cddr.cdrCallDate between '''+@.b+''' and '''+@.e+''' group by cddr.meraRecordId) AS cdr1 join tblVoIPCDRTemp AS cdr WITH (NOLOCK) on (cdr1.cdrNativeId = cdr.cdrNativeId) left join tblUser uu on (cdr.vrUserName=uu.userUnixName) left JOIN tblCustomer cc on (uu.CustId = cc.CustId) ' + @.c
end

if @.qryMode=10 OR @.detailMode=10
begin
set @.q=@.q +' left outer JOIN (SELECT * FROM openquery(routing, ''SELECT * FROM gateways'') ) gateways ON gateways.[Name] = (case when patindex(''sip/%'',lower(cdr.cdrDstChannel)) > 0 then (substring(cdr.cdrDstChannel, 5, (len(cdr.cdrDstChannel)-4) - patindex(''%-%'',reverse(cdr.cdrDstChannel)))) end) ' +@.c
end

--if @.qryMode=10 begin set @.q=@.q + ' join tblCustomer cust on (vv.custID = c.custId) join X1Customer x1c on (c.x1CustId = x.ID) '+@.c end

-- join user table
--set @.q=@.q +'join tblUser u on u.userId=cd.userId '

-- join status, destination tables
--set @.q=@.q +'join tblVoIPCallstatus cs on cs.vcsId=cd.vcsId '
if @.vcsId>0
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
set @.f=@.f +' cdr.vcsId='+cast(@.vcsId as varchar)+' '+@.c
end
else
begin
set @.f=@.f +@.c
end

--if @.userId>0 set @.q=@.q +'and u.userId='+cast(@.userId as varchar)+' '
--if @.custId>0 set @.q=@.q +'and u.custId='+cast(@.custId as varchar)+' '+@.c else set @.q=@.q +@.c

if @.userId>0
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
set @.f=@.f +' cdr.userId='+cast(@.userId as varchar)+' '+@.c
end
else
begin
set @.f=@.f +@.c
end

if @.custId>0
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
set @.f=@.f +' cdr.custId='+cast(@.custId as varchar)+' '+@.c
end
else
begin
set @.f=@.f +@.c
end

--set @.q=@.q +' join tblVoIPRate vr on ((vr.vtrID = cd.vtrID) AND (vr.vvdId = cd.vvdId) AND (vr.vdsID = cd.vdsID)) ' -- Join voipRATE table
--set @.q=@.q + ' join tblVoIPBillingStructure vbs on (vbs.vbsID = vr.vbsID) ' -- Join voipBillingStructure table

if @.vdsId>0
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
set @.f=@.f +' cdr.vdsId='+cast(@.vdsId as varchar)+' '+@.c
end
else
begin
set @.f=@.f +@.c
end

if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
if @.systemid='1' set @.f=@.f +' ( '
set @.f=@.f +' uu.systemid='''+(@.systemid)+''' '+@.c
if @.systemid='1' set @.f=@.f +' OR uu.systemid IS NULL ) '+@.c

if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
set @.f=@.f +' cdrActive=1'+@.c

if len(@.vendor)>1
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
set @.f=@.f +' cc.x1CustId='''+(@.vendor)+''' '+@.c
end

if len(@.vendorUserId)>1
begin
if len(@.f)>0 set @.f=@.f +' and ' else set @.f='where '
set @.f=@.f +' uu.userId='''+(@.vendorUserId)+''' '+@.c
end

-- join month and day soft tables
--if @.qryMode=6 OR @.qryMode=7 OR @.qryMode=8 OR @.qryMode=9
--Begin
set @.q=@.q +'join fnSplit('''+@.mm+''','' '') mm on mm.idx=month(cdr.cdrCallDate)-1 ' +@.c
set @.q=@.q +'join fnSplit('''+@.dd+''','' '') dd on dd.idx=datepart(dw,cdr.cdrCallDate)-1 ' +@.c
--End

-- add filter
if len(@.f)>0 set @.q=@.q +@.f

-- add grouping for summary modes
if @.qryMode=1 set @.q=@.q +'' +@.c
else if @.qryMode=3 begin set @.q=@.q +'group by cdr.vdsId, '+@.g+' ' +@.c end
else if @.qryMode in (2,4,5,6,7,8,9,10,11,12) begin set @.q=@.q +'group by '+@.g+' ' +@.c end

-- add sorting to detail mode
if len(@.sortBy)>0 and @.qryMode<>1 set @.q=@.q +'order by ' +@.sortBy +@.c

-- exec
print @.q
exec(@.q)|||Ok.

A few questions:
Please could you post a typical result from the "print @.q" line. Obviously this is building up a mega-flexible query so there are a lot of very different statements that could be built up but seeing one would be helpful.
Why are you storing cdrUserId and cdrUserName as attributes in the table? Are you familiar with normalisation? http://www.tonymarston.net/php-mysql/database-design.html
Can a cdrUserName really be in excess of 4000 international characters? Same for pretty well all the text fields.
There are no indexes, foreign keys, primary keys or constraints of any kind correct?
Also - you mentioned that this query joins to a second table. Please could you post the DDL for that too.|||I know there is no normalization here but, this system is a legacy system that built from 1990 with many programmer with differenty ideas, so i have to only optimize this table without touch anything else

so, i`m stucked|||i can`t use index because i have to insert about 6000 row every 10min
and index will slow it down

sorry, but 6000 rows in 10min is cake.|||At least from my perspective, 6000 rows in ten seconds might possibly be a challenge on a really busy server, but 6000 rows in ten minutes isn't enough work to even make a noticable bump on the performance counters on any server I'd consider running in production. This is just plain a moot point in my mind until you set up a test to see what (if any) impact adding the indicies would have.

-PatP|||I will do the following :
1- create clustered index on column Date
2- try to create temp table that will hold either summerized data or the columns that i need only|||I'm not sure the clustered index on date is necessary. That was one of reasons I asked how many rows are returned. If it is typically 40 then a non clustered index might be best.

Please could you post the answers to my last post (I know you answered the denormalised bit the rest is important too).|||any help with this problem|||See post #26 (http://www.dbforums.com/showpost.php?p=6286611&postcount=26)|||any help with this problemLol. Ok that does it. You can't be bothered reading questions and tell us they are "irrelevant" if you do.

Read up on indexes and figure it out.
http://www.sql-server-performance.com/ & BoL
Read up on appropriate data types for your table.
Read up on dynamic SQL and creating all-things-to-all-men procedures.
http://www.sommarskog.se/dynamic_sql.html|||I do the following as a solution :
1- Create View with only requried columns in table "I have on the table 71 column and i only use 16 in joins and in my stored procedural" -- that for lage table with 37,000,000 row
2-Create New table that hold some joins and some aggregation function that calculate at run time
3-Remove the joins and aggregation that occur in the Stord procedural with this new table
4-Create Clustered Index for that table
5-Create new Stored Procedural that will fill the new table each time a new data enter to the oreginal table|||If you don't have indexes then you have a heap. You can get better insert performance with an appropriate clustered index than a heap.


That can not be true|||Monotonically increasing -> quicker insert performance than a heap. I can try to dig out the source if you like (read it ages ago).|||How can inserts be faster with an index..compare having to find the correct page to put the insert (or if the page is full, then a new page), as compared to just putting at the last page?

Yes please dig up that reference, because I don't belive it|||so, create or no index|||How can inserts be faster with an index..compare having to find the correct page to put the insert (or if the page is full, then a new page), as compared to just putting at the last page?

Yes please dig up that reference, because I don't belive itThis isn't the reference I had in mind but is something:

From Kimberly Tripp (soon to be Randal if I recall correctly - I hope I got the correct guru).
http://www.sqlskills.com/blogs/kimberly/CommentView.aspx?guid=ddd63dda-4855-4724-997c-d1db2ac3fa02

Inserts are faster in a clustered table (but only in the "right" clustered table) than compared to a heap. The primary problem here is that lookups in the IAM/PFS to determine the insert location in a heap are slower than in a clustered table (where insert location is known, defined by the clustered key). Inserts are faster when inserted into a table where order is defined (CL) and where that order is ever-increasing. I have some simple numbers but I'm thinking about creating a much larger/complex scenario and publishing those. Simple/quick tests on a laptop are not always as "exciting". But - this is a well documented issue (IAM/PFS lookups) and poor performance on a heap is also referenced in this KB: PRB: Poor Performance on a Heap. note: this KB is quite dated and I don't actually agree with everything in this article however, the general concern of poor performance for inserts is still true on SQL Server 2005.The KB article she refers to:
http://support.microsoft.com/kb/297861/en-us|||In SQL Server 7.0, and later, SQL Server generally optimizes inserts into a heap with the assumption that saving space is more important than performance. That is the tradeoff you choose to make when you decide to leave a table as a heap. Therefore, an insert into a heap often spends time searching for a location to insert a new row. On the other hand, an insert to a clustered table does not have to spend time searching for space. For more details about how the space is allocated, see the "Managing Space Used by Objects" topic in SQL Server Books Online.

I'm floored...how is that possible.

Let's say you have (god forbid) an IDENTITY Column. Doesn't that incur hotspots?

And let's say you have a natural key. Doesn't the database have to skip around to find the appropriate pages...and doesn't it not only need to add the data, and manage the index...

I still don't buy it|||If you have a natural key, odds are it will not be "ever increasing".

As for the Identity, I would probably rather have a hot spot at the end of the table, than use GUIDs, and have page splits all over the table.|||I'm floored...how is that possible.

Let's say you have (god forbid) an IDENTITY Column. Doesn't that incur hotspots?

And let's say you have a natural key. Doesn't the database have to skip around to find the appropriate pages...and doesn't it not only need to add the data, and manage the index...

I still don't buy itHotspots - not a problem since 7.0 (where you been grandad?) (EDIT - in fact a hotspot is now considered a good thing - less pages in memory).

Natural key (I presume you mean not monotonically increasing) - you are quite right - this would perform worse than a heap. You would also get page splits.


Interesting though huh? Easier for SS to insert into a monotinical CI and into the B-Tree than just into a heap. Who would have confuggered it.|||Only partially sniped ;)|||I just went digging into my DB2 OS/390 manuals and a table with no idex is faster

M$ comes up with all of these "features"

I wonder how it's done...I still don't believe it...But I've seen alot of thing I couldn't believe|||I know in Sybase, there is a setting (or was a setting) that affected the decision Sybase made about adding a new page, or looking through the table for a sufficiently empty page. The fact of it all is Microsoft was faced with a choice, so they made one in favor of reducing database size, as opposed to performance. For the vast majority of tables with no primary key, this performance drop is not noticeable. Especially since most applications that can stand to have no primary keys on their tables are likely using no indexes at all, or looping through tables using cursors.|||As I recall Brett you need to revisit your logging tables' schemas - I remember a SQLTeam thread where I made my first ever post that impplied that you log stuff to heaps. I couldn't really say owt then being a fresh faced n00b rather than the seasoned pro you see before you today.|||well, when I'm logging all of sproc calls, I don;t have an index because I thought (yes I know, dangerous) that it would be fatser.

So should I put a clustered index on my datetime column, or sproc name?

I am so cornfused

:S|||So should I put a clustered index on my datetime column, or sproc name?I created an identity for mine & made it clustered. It was originally on the datetime column BUT it turned out I had one bit of looping code that called a sproc - the loop was faster than once every 3.3 milliseconds which meant I could not have a unique constraint on the datetime column. Probably the ideal would be a superkey - (DateColumn, IdentityColumn) then you can do nice range scans on the datecolumn.

You don't really mean on the sproc name do ya Brett? :shocked: :)|||That can not be true

Brett asked me to comment... Kimberly's right. Depending on the insert pattern, and as long as you pick the right index key, it'll be faster than inserts into a heap because of the free space search.

Why would IBM manuals have any bearing on how SQL server works??

Now I'm going away until next week :)

Btw - http://blogs.msdn.com/sqlserverstorageengine/archive/2007/07/30/announcements.aspx|||Sure, Brett. Bring in the big guns.

And congrats, Paul.|||Brett asked me to comment... Kimberly's right. Depending on the insert pattern, and as long as you pick the right index key, it'll be faster than inserts into a heap because of the free space search.

Thanks Paul...ummmmm, now which is the right index key?

Why would IBM manuals have any bearing on how SQL server works??

They don't, it's just my frame a of reference on how things work...I've only been doing sql server for 10 years...DB2, closer to 20|||The "right" key is one that lets SQL Server find the place to insert quickly without causing too many page splits. So your datetime column sounds like the one you would want to use (provided that means the date and time the procedure was invoked). The only time you would risk page splits is at daylight saving time, but that is only one hour per year.|||Now I'm going away until next week :)

Btw - http://blogs.msdn.com/sqlserverstorageengine/archive/2007/07/30/announcements.aspxCongrats Paul. BTW - you are half cut off your piccy on my browser. Better piccy of the happy couple: http://www.sqlskills.com/blogs/kimberly/2007/07/31/OurPerfectWeekend.aspx

And Brett - I can't believe my word was not enough and you had to ask for both links and the opinon of one of MS's premier gurus :shocked: For shame.|||Poots

I still don't belive it, and I'm going to have to do some tests

And from what I've read, it seems to be very exclusive as to when it's faster

How is stuffing rows onto the last page slower the skipping around to all different pages?

I still don't get it, and I plan to prove it|||I just want to say - I agree with Bretts logic! ;)|||I just want to say - I agree with Bretts logic! ;)You probably don't realize that posting something like that is an indicator that you are likely teetering precariously on the edge between normalcy and madness.|||Yes... so what's your point? :p|||OMG, I forgot to have a point. Damn. I better hit the bar at lunch and get my life's bearings back again.|||*Lol*

I better hit the bar at lunch

Yes, yes you should :beer:|||I thought I was driving Paul to Madness...then I realized it's just a 3 foot putt|||I thought I was driving Paul to Madness...then I realized it's just a 3 foot puttHell, I've never been farther away from it than the big clown head at the end of the course!|||How is stuffing rows onto the last page slower the skipping around to all different pages?I don't believe it is.

If you are skipping around pages rather than "stuffing them onto the last page" then you must have a key that is not ever increasing. This would be slow - much slower than a heap.

The difference is between a heap and an ever increasing clustered index. For both of these you would never skip around pages - you would fill one page and then move to the next fill that and move to the next. The performance gain for the ever increasing index is that the engine knows what the next page will be before it has finished filling the current page. When inserting to a heap the engine only figures out what the next page will be once it fills a page and instead of just filling the first data page it finds it does some search to find one towards the beginning of the file. It is this search that slows things down. I guess the point is that you would only really notice on high insert tables (or tables with moderate inserts of large rows of data).

The above is just my understanding of what's going on.

Wednesday, March 21, 2012

Problem with 1 Table in MSDE DB

Hello all.

First I will be the first to say that I'm very inexperienced when it comes to working with MS SQL DBs. I'm doing my best to learn though.

Here is my problem. I have a piece of software that connects up to an MSDE instance. Within this instance there is a database called TTUSER. And within the TTUSER database, there are several tables, one of which called User. I can not seem to do anything with this table. For example when I just try to see the contents of the UserID column, I get:

1> select UserID from User
2> go
Msg 156, Level 15, State 1, Server <MyMsdeServerName>, Line 1
Incorrect syntax near the keyword 'User'.

However, when I try the exact same command above, but use the Logon table instead of the User table, it works just fine, and I see the contents of the UserID column from the Logon table.

I also tried copying the User Table with this:

1> select * into Test from User
2> go
Msg 156, Level 15, State 1, Server 10250-JORUM, Line 1
Incorrect syntax near the keyword 'User'.

And again, if I just substitute the User table with the Logon table, it copies just fine. Both of these tables, Logon and User, are in the same database, TTUser.

I would just like to be able to view the contents of the User table from command line, and maybe send it into a text file. Thanks for your help.

Jnuw"User" is a keyword. Try this:

select *
from [User]|||MCrowley, thank you! That did the trick.