Showing posts with label returns. Show all posts
Showing posts with label returns. Show all posts

Wednesday, March 28, 2012

Need Help 1505 Error

Hello All
I have a SQL 6.5 Server running on Service Pack 5a with a hotfix.
select @.@.version returns:
Microsoft SQL Server 6.50 - 6.50.451 (Intel X86)
Jul 1 1999 01:11:25
Copyright (c) 1988-1997 Microsoft Corporation

I am getting an error something like this:
Error 1505 Create unique index aborted on duplicate key. Primary key is '847474 '

When this is happening is after copying some data and during the creation of an index. I have 2 tables one called ITEM_INVENTORY the other ITEM_INVENTORY_WORK. The only difference between them is that the WORK table has an identity column.

I use a stored procedure to perform the following steps:
1. Truncate the table ITEM_INVENTORY
2. Drop all the indexes on ITEM_INVENTORY
3. Copy the data from the ITEM_INVENTORY_WORK table to the ITEM_INVENTORY table in 10000 row chunks using:
BEGIN TRAN
INSERT INTO ITEM_INVENTORY
SELECT <(COLUMN LIST)>
FROM ITEM_INVENTORY_WORK
COMMIT TRAN
4. Recreate all the indexes.

During step 4 (recreate indexes) the process fails and returns a 1505 error while creating the UNIQUE index: CREATE UNIQUE INDEX ITEM_INVENTORY_idx1 ON dbo.ITEM_INVENTORY(IC_ITEM_NO, CORP_CODE)

Now here is the kicker. There are no duplicates. I've checked and re-cheked and there are no duplicate records. I think this may be a bug, but I don't know. Has anyone encountered this problem and have any ideas on how to solve it?It's not about duplicare records - it's about duplicate IC_ITEM_NO, CORP_CODE.

Run this:

select IC_ITEM_NO, CORP_CODE
from ITEM_INVENTORY
group by IC_ITEM_NO, CORP_CODE
having count(*) > 1

See what It returns. There are no miracles|||Hi I ran the query:
select IC_ITEM_NO, CORP_CODE
from ITEM_INVENTORY
group by IC_ITEM_NO, CORP_CODE
having count(*) > 1

and I get nothing back. Like I said no duplicates.
The other crazy thing is the WORK table is truncated and recreated each day in a similar way but it does not error when recreating the index.

Regards
CaptainEstock|||Try this:
drop table ITEM_INVENTORY
select * into WORK

drop IDENTITY column
recrate indexes

Do not forget to set DB option to allow Bulk copy/select into|||Sorry,

select * into item_inventory
from work|||I can't drop columns in SQL 6.5

I might be able to do a SELECT with the column names...sql

Monday, March 19, 2012

Need Answer PLS - excel export file size changed on re-save

I have a report that ran and returns a large amount a data. When I export the report to excel it takes 3 minutes to export. The file size when I open the xls file is 24.1MB. I choose save as and give it another name ... then open the xls I just saved and the size is 9.79MB. Why is the file size different on the re-saved file than the originally exported file? This was reported by a user and I didnt believe the file size would change until I tried it myself ...sorry ... forgot to add that I am running RS2005 sp1|||If you have a lot of

string values in the report that can be represented as single byte strings,

that’s probably where Excel is making a difference. In Reporting Services we

always write strings as 2-byte Unicode, but Excel will always try to compress to

single byte when possible.

Need Advise on Stored Procedure

Little rusty on my SQL but here is what I need. Currently have a stored procedure that returns numerical data for 8 different element readings. ( Carbon, Silicon, Sulfur, etc ). This data is then put into a datagrid on an asp.net page and shows the readings for each test.
On my asp .net page... they only want data that is out of the specified ranges to be shown ( EX: > 1.6 AND < 2.0 ). Currently it is setup on the page to change the font color to red of data of its range but now they don't want data to be shown at all if for that one test everything is in its range.
So how could I write my Where clause to check the 8 different element ranges and only need one of them to be true in order to show.
Could I use an If / Then statement?
Any help is appreciated... Sorry this is quickly done but got to have it done soon.

Show your table layout. Also, are the ranges for all elements the same, or element specific?

Saturday, February 25, 2012

Nee help - How To get AVG in his situation?

Hi All,
Below is my initial query, that returns totals for each w within the
month specified. I hard coded the W Columns to make it easier to work
with. This works fine.
/*---*/
Select T1.DataSource AS [Service Line],
COUNT(T1.PoNumber) AS [Total Of PONumber],
Sum(Case When T1.ReqSubmitDate
Between '04/01/2005' AND '04/2/2005' Then 1 End) [04/2/2005],
Sum(Case When T1.ReqSubmitDate
Between '04/03/2005' AND '04/9/2005' Then 1 End) [04/9/2005],
Sum(Case When T1.ReqSubmitDate
Between '04/10/2005' AND '04/16/2005' Then 1 End) [04/16/2005],
Sum(Case When T1.ReqSubmitDate
Between '04/17/2005' AND '04/23/2005' Then 1 End) [04/23/2005],
Sum(Case When T1.ReqSubmitDate
Between '04/24/2005' AND '04/30/2005' Then 1 End) [04/30/2005]
FROM OPW AS T1,
(SELECT PoNumber
FROM OPW
GROUP BY PoNumber
HAVING COUNT(*)>1) AS T2
WHERE (T1.PoNumber = T2.PoNumber) AND (T1.ReqSubmitDate BETWEEN '04/01/2005'
AND '04/30/2005')
GROUP BY T1.DataSource
/*---*/
The current resulting data is:
[Service Line] [Total Of PONumber] [04/2/2005] [04/9/2005] [04/16/2005]
[04/23/2005] [04/30/2005]
EVPN 4 NULL NULL 4 NULL NULL
MNS 526 NULL 209 313 NULL 4
/*---*/
Now, one of my tasks assign to me is to find the average cycle time for each
w per [Service Line]. This will include the following fields to the
query:
REQCreateDate DateTime,
REQCreateTime VarChar(10),
ReqSubmitTime VarChar(10),
ReqSubmitDate DateTime (This one is already used within the above query)
So, I'm thinking I need to concatinate the following columns, then get the
total number per w and derive the average:
T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME) AS RC,
T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME) AS RS
I hope I am making sense and you can help m understand this.
Thanks for taking the time though.
John.John,
If you can provide some sample data and also show
the exact results you want, it will be easier to help. You
may know exactly what "average cycle time" means, but
I don't. Sample data will also help to show why and how
you are storing values like REQCreateTime as VarChar(10),
since the time columns appear to be important.
See http://www.aspfaq.com/etiquett_e.asp?id=5006
Steve Kass
Drew University
John Rugo wrote:

>Hi All,
>Below is my initial query, that returns totals for each w within the
>month specified. I hard coded the W Columns to make it easier to work
>with. This works fine.
>/*---*/
>Select T1.DataSource AS [Service Line],
> COUNT(T1.PoNumber) AS [Total Of PONumber],
> Sum(Case When T1.ReqSubmitDate
> Between '04/01/2005' AND '04/2/2005' Then 1 End) [04/2/2005],
> Sum(Case When T1.ReqSubmitDate
> Between '04/03/2005' AND '04/9/2005' Then 1 End) [04/9/2005],
> Sum(Case When T1.ReqSubmitDate
> Between '04/10/2005' AND '04/16/2005' Then 1 End) [04/16/2005],
> Sum(Case When T1.ReqSubmitDate
> Between '04/17/2005' AND '04/23/2005' Then 1 End) [04/23/2005],
> Sum(Case When T1.ReqSubmitDate
> Between '04/24/2005' AND '04/30/2005' Then 1 End) [04/30/2005]
>FROM OPW AS T1,
>(SELECT PoNumber
> FROM OPW
> GROUP BY PoNumber
> HAVING COUNT(*)>1) AS T2
>WHERE (T1.PoNumber = T2.PoNumber) AND (T1.ReqSubmitDate BETWEEN '04/01/2005
'
>AND '04/30/2005')
>GROUP BY T1.DataSource
>/*---*/
>The current resulting data is:
>[Service Line] [Total Of PONumber] [04/2/2005] [04/9/2005] [04/16/2005]
>[04/23/2005] [04/30/2005]
>EVPN 4 NULL NULL 4 NULL NULL
>MNS 526 NULL 209 313 NULL 4
>/*---*/
>Now, one of my tasks assign to me is to find the average cycle time for eac
h
>w per [Service Line]. This will include the following fields to the
>query:
>REQCreateDate DateTime,
>REQCreateTime VarChar(10),
>ReqSubmitTime VarChar(10),
>ReqSubmitDate DateTime (This one is already used within the above query)
>So, I'm thinking I need to concatinate the following columns, then get the
>total number per w and derive the average:
>T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME) AS RC,
>T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME) AS RS
>I hope I am making sense and you can help m understand this.
>Thanks for taking the time though.
>John.
>
>|||The times are stored in a varchar format because they are derived solely
from an Excel Spreadsheet import that has the time in a spererate column,
and I was asked to mimic the data structure of the excel file. I don't like
it ether :(.
The Cycle Time is the Number of Minutes between ReqCreated Date/Time and
ReqSubmit Date/Time.
At the bottom of the my current message I have my newest version of the
query that at least shows the total Cycle Times per w. But I need to
show the averages, not the total.
Thanks very much for helping me.
/*Data*/
/*--*/
Select DataSource, PoNumber, REQCreateDate, REQCreateTime, ReqSubmitDate,
ReqSubmitTime
FROM OPW
DataSource | PoNumber | REQCreateDate | REQCreateTime | ReqSubmitDate |
ReqSubmitTime
EVPN PO82959 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
9:18:26
EVPN PO82956 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
9:18:26
EVPN PO82957 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
9:18:26
EVPN PO82958 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
9:18:26
EVPN PO82957 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
9:18:26
EVPN PO82959 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
9:18:26
MNS PO82755 2005-03-30 00:00:00.000 4:42:27 2005-03-31 00:00:00.000 1:33:18
MNS PO82840 2005-04-13 00:00:00.000 3:31:16 2005-04-14 00:00:00.000 10:27:57
MNS PO81971 2005-03-29 00:00:00.000 4:36:08 2005-03-29 00:00:00.000 5:03:08
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
MNS PO81971 2005-03-29 00:00:00.000 4:36:08 2005-03-29 00:00:00.000 5:03:08
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
MNS PO82968 2005-04-15 00:00:00.000 2:35:37 2005-04-15 00:00:00.000 2:42:01
MNS PO81971 2005-03-29 00:00:00.000 4:36:08 2005-03-29 00:00:00.000 5:03:08
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
/*Newest Query*/
/*--*/
Select T1.DataSource AS [Service Line],
COUNT(T1.PoNumber) AS [Total Of PONumber],
Sum(Case When T1.ReqSubmitDate
Between '04/01/2005' AND '04/2/2005' Then
CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
(T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
Decimal(9,2))
End) [04/2/2005],
Sum(Case When T1.ReqSubmitDate
Between '04/03/2005' AND '04/9/2005' Then
CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
(T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
Decimal(9,2))
End) [04/9/2005],
Sum(Case When T1.ReqSubmitDate
Between '04/10/2005' AND '04/16/2005' Then
CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
(T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
Decimal(9,2))
End) [04/16/2005],
Sum(Case When T1.ReqSubmitDate
Between '04/17/2005' AND '04/23/2005' Then
CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
(T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
Decimal(9,2))
End) [04/23/2005],
Sum(Case When T1.ReqSubmitDate
Between '04/24/2005' AND '04/30/2005' Then
CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
(T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
Decimal(9,2))
End) [04/30/2005]
FROM OPW AS T1,
(SELECT PoNumber
FROM OPW
GROUP BY PoNumber
HAVING COUNT(*)>1) AS T2
WHERE (T1.PoNumber = T2.PoNumber) AND (T1.ReqSubmitDate BETWEEN '04/01/2005'
AND '04/30/2005')
GROUP BY T1.DataSource
/*--*/
"Steve Kass" <skass@.drew.edu> wrote in message
news:u8Ejbk$SFHA.3620@.TK2MSFTNGP09.phx.gbl...
> John,
> If you can provide some sample data and also show
> the exact results you want, it will be easier to help. You
> may know exactly what "average cycle time" means, but
> I don't. Sample data will also help to show why and how
> you are storing values like REQCreateTime as VarChar(10),
> since the time columns appear to be important.
> See http://www.aspfaq.com/etiquett_e.asp?id=5006
> Steve Kass
> Drew University
> John Rugo wrote:
>|||John,
Did you try using AVG() instead of SUM() ? To be safe from rounding
surprises, write any AVG() expression as AVG(1.0*(yourvalue)) if yourvalue
is an integer.
SK
John Rugo wrote:

>The times are stored in a varchar format because they are derived solely
>from an Excel Spreadsheet import that has the time in a spererate column,
>and I was asked to mimic the data structure of the excel file. I don't lik
e
>it ether :(.
>The Cycle Time is the Number of Minutes between ReqCreated Date/Time and
>ReqSubmit Date/Time.
>At the bottom of the my current message I have my newest version of the
>query that at least shows the total Cycle Times per w. But I need to
>show the averages, not the total.
>Thanks very much for helping me.
>/*Data*/
>/*--*/
>Select DataSource, PoNumber, REQCreateDate, REQCreateTime, ReqSubmitDate,
>ReqSubmitTime
>FROM OPW
>DataSource | PoNumber | REQCreateDate | REQCreateTime | ReqSubmitDate |
>ReqSubmitTime
>EVPN PO82959 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
>9:18:26
>EVPN PO82956 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
>9:18:26
>EVPN PO82957 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
>9:18:26
>EVPN PO82958 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
>9:18:26
>EVPN PO82957 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
>9:18:26
>EVPN PO82959 2005-04-14 00:00:00.000 11:39:58 2005-04-14 00:00:00.000
>9:18:26
>MNS PO82755 2005-03-30 00:00:00.000 4:42:27 2005-03-31 00:00:00.000 1:33:18
>MNS PO82840 2005-04-13 00:00:00.000 3:31:16 2005-04-14 00:00:00.000 10:27:5
7
>MNS PO81971 2005-03-29 00:00:00.000 4:36:08 2005-03-29 00:00:00.000 5:03:08
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>MNS PO81971 2005-03-29 00:00:00.000 4:36:08 2005-03-29 00:00:00.000 5:03:08
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>MNS PO82968 2005-04-15 00:00:00.000 2:35:37 2005-04-15 00:00:00.000 2:42:01
>MNS PO81971 2005-03-29 00:00:00.000 4:36:08 2005-03-29 00:00:00.000 5:03:08
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>MNS PO82838 2005-04-14 00:00:00.000 3:37:07 2005-04-14 00:00:00.000 4:51:12
>/*Newest Query*/
>/*--*/
>Select T1.DataSource AS [Service Line],
> COUNT(T1.PoNumber) AS [Total Of PONumber],
> Sum(Case When T1.ReqSubmitDate
> Between '04/01/2005' AND '04/2/2005' Then
> CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
> (T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
>Decimal(9,2))
> End) [04/2/2005],
> Sum(Case When T1.ReqSubmitDate
> Between '04/03/2005' AND '04/9/2005' Then
> CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
> (T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
>Decimal(9,2))
> End) [04/9/2005],
> Sum(Case When T1.ReqSubmitDate
> Between '04/10/2005' AND '04/16/2005' Then
> CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
> (T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
>Decimal(9,2))
> End) [04/16/2005],
> Sum(Case When T1.ReqSubmitDate
> Between '04/17/2005' AND '04/23/2005' Then
> CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
> (T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
>Decimal(9,2))
> End) [04/23/2005],
> Sum(Case When T1.ReqSubmitDate
> Between '04/24/2005' AND '04/30/2005' Then
> CAST(DateDiff(hh, (T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME)),
> (T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME))) As
>Decimal(9,2))
> End) [04/30/2005]
>FROM OPW AS T1,
>(SELECT PoNumber
> FROM OPW
> GROUP BY PoNumber
> HAVING COUNT(*)>1) AS T2
>WHERE (T1.PoNumber = T2.PoNumber) AND (T1.ReqSubmitDate BETWEEN '04/01/2005
'
>AND '04/30/2005')
> GROUP BY T1.DataSource
>/*--*/
>"Steve Kass" <skass@.drew.edu> wrote in message
>news:u8Ejbk$SFHA.3620@.TK2MSFTNGP09.phx.gbl...
>
>
>