|
Mangesh6786 wrote: Its very very urgent. We're volunteers.
Try hurrying a random passer-by, it won't work.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
On which system did you develop the package? Is the connection manager set to use "localhost"?
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
Need to write extract file providing 2 employee emergency contacts with one phone number each in one record. Going to order by emergency contact name when selecting which contact and sort by phone type when selecting phone. I'm at a loss at how to do this and would appreciate any help
Fields in Row:
EmpNum EmergencyContact1 Relation1 PhType1 Phone1 EmergencyContact2 Relation2 PhType2 Phone2
EmpNum EmpEmergencyContact Relation PhType Phone
123456 Rick Grimes SP Cell 9999999999
123456 Rick Grimes SP Work 8888888888
123456 Daryl Dixon FR Cell 7777777777
123456 Daryl Dixon FR Home 3333333333
123456 Maggie Greene CH Cell 5555555555
123456 Maggie Greene CH Home 6666666666
|
|
|
|
|
SELECT * FROM
(
SELECT EMpNum "EmpNum", EmergencyContact1 "Name", Relation1 "Relation", PhType1 "Phone Type", Phone1 "Phone"
FROM EMERGENCY_CONTACT
UNION
SELECT EMpNum "EmpNum", EmergencyContact2 "Name", Relation2 "Relation", PhType2 "Phone Type", Phone2 "Phone"
FROM EMERGENCY_CONTACT
) EMERGENCY_CONTACTS
ORDER BY "EmpNum", "Name", "Phone Type"
|
|
|
|
|
Something like this should work:
WITH cteOrderedContacts As
(
SELECT
EmpNum,
EmpEmergencyContact,
Relation,
PhType,
Phone,
ROW_NUMBER() OVER (PARTITION BY EmpNum ORDER BY EmpEmergencyContact) As RN
FROM
SourceData
)
SELECT
C1.EmpNum,
C1.EmpEmergencyContact As EmergencyContact1,
C1.Relation As Relation1,
C1.PhType As PhType1,
C1.Phone As Phone1,
C2.EmpEmergencyContact As EmergencyContact2,
C2.Relation As Relation2,
C2.PhType As PhType2,
C2.Phone As Phone2
FROM
cteOrderedContacts As C1
LEFT JOIN cteOrderedContacts As C2
ON C2.EmpNum = C1.EmpNum
And C2.RN = C1.RN + 1
WHERE
(C1.RN & 1) = 1
ORDER BY
C1.EmpNum,
C1.RN
;
http://www.sqlfiddle.com/#!3/21e9e/4/0[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I should hope that you have translation tables for Relation and PhType -- you can add some sort of prioritization there to better control ordering.
RelationshipType
ID Abbr Name Priority
1 SP Spouse 1
2 FR Friend 3
3 CH Child 2
PhoneType
ID Abbr Name Priority
1 Cell Mobile 1
2 Work Office 3
3 Home Home 2
Such translation table also allow you to use referential integrity and can reduce the amount of space used by the database (not so much a concern these days).
Also, it allows your application code to use an enumeration rather than hard-coded string values.
Then follow Richard Deeming's advice.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
guys;
I trying to design a query that returns products ordered based on a self-reference foreign key (just like a linked list). I tried to make a recursive query (CTE), but i couldn't return the records as the table below.
product_id | next_id | product_name
5 | 3 | product 5
3 | 2 | product 3
2 | 4 | product 2
4 | 1 | product 4
1 | null | product 1
I am wondering if you can help me with this.
Help people,so poeple can help you.
|
|
|
|
|
finally, i designed a query that returns the desired results. its the following one.
create table products(product_id int, next_id int, product_name nvarchar(50));
insert into products(product_id, next_id, product_name)
Values (1, null, N'product1')
,(2, 4, N'product2')
,(3, 2, N'product3')
,(4, 1, N'product4')
,(5, 3, N'product5');
WITH LinkedList (product_id, next_id, product_name, Level)
AS
(
SELECT e.product_id, e.next_id, e.product_name,
0 AS Level
FROM products AS e
WHERE e.next_id IS NULL
UNION ALL
SELECT e.product_id, e.next_id, e.product_name,
Level + 1
FROM products AS e
INNER JOIN LinkedList AS d
ON e.next_id = d.product_id
)
SELECT product_id, next_id, product_name
FROM LinkedList
Order by Level desc;
drop Table products;
Help people,so poeple can help you.
|
|
|
|
|
Hello everyone,
I'm trying to understand this function.
Someone wrote this piece of code and I would like to use to do something simular.
On a daily basis we read .txt files into our SQL database through SSIS.
The data that's going through is growing fast and takes a long time to process. (for example a year of data is read every day into the db)
I want to make a dayset so that we only read one single day into the DB on top of the existing data and not the whole year.
Someone wrote this peace of code:
Select * , ROW_NUMBER() OVER (PARTITION BY PK_Assignment ORDER BY DATE, TIME) as LineNbr
from ProductivityColliDagSet
I was wondering what the Partition By statement means.
My guess was that you have to place the fields there that makes the record unique.
Can someone help me out with this because I read so many things on the internet and still I don't understand.
Also I don't have much experience with SQL, just the basics.
Ambertje
|
|
|
|
|
|
I've seen this already but still not clear to me sorry
|
|
|
|
|
It determines the grouping. Play around with below script;
BEGIN TRANSACTION
CREATE TABLE SomeTest(
Field1 INTEGER,
Field2 CHAR(1),
Data VARCHAR(50))
INSERT INTO SomeTest VALUES (1, 'C', 'Test')
INSERT INTO SomeTest VALUES (1, 'A', 'Test')
INSERT INTO SomeTest VALUES (7, 'C', 'Test')
INSERT INTO SomeTest VALUES (7, 'A', 'Test')
INSERT INTO SomeTest VALUES (4, 'C', 'Test')
SELECT *
, ROW_NUMBER() OVER ( PARTITION BY Field2 ORDER BY Field1 )
FROM SomeTest
ROLLBACK
If you change the field that's being partitioned by to "Field1", you'll see a different grouping in the result-set (with each group receiving a unique numbering).
It's often used with a primary key because some idiot forgot to add an identity-field
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: some idiot forgot to added an identity-field
FTFY
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
I was more expecting at someone pointing out the option to count items based on particular groupings.
Sounds like you really dislike the identity-field?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Real databases use a sequence.
|
|
|
|
|
Begone with your Oracle concepts bah humbug!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Eddy,
This example made it clear to me, I think I understand what it's doing.
Now I can try to rewrite the code to my needs.
Thank you for taking the time to help me
Ambertje
|
|
|
|
|
Ambertje wrote: I want to make a dayset so that we only read one single day into the DB on top of the existing data and not the whole year.
I don't see what that has to do with partitions - the database of course wouldn't have anything to do with reading files.
Ambertje wrote: and takes a long time to process.
Someone should optimize that process. I wouldn't be surprised if that means moving it out of SSIS but maybe it can be sped up as is.
Normally one profiles a process by actually timing the various parts and then using that data to determine where things can be made faster.
Although your description might suggest that every day you read the previous years data. If so one obvious optimization there would be to some producing a file that has a years worth of data. How one does that depends on the data.
|
|
|
|
|
The best way to understand this is to create a couple of tables and experiment.
It is quite difficult to explain what is going on in a partition statement - the closest I can get is transposing data in Excel.
However that does not explain how to go about transposing the data.
Think of it as changing column headings into row contents and row contents into column headings.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Many thanks to everyone who is helping me, I really appreciate the effort you put into it to help newbe's.
Ambertje
|
|
|
|
|
Hi everyone,
I am creating a query to my database using SQL Server Management Studio
There is a data error in my image field of my row. I still can select another fields, but when I select content of the image field I get below error:
My query:
select diagram from Mytable where id = 5
Error 1:
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
When I tried to delete this row. I got another error (Error 2):
SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0x4da7af2c; actual: 0xda5e9af7). It occurred during a read of page (1:40403) in database ID 6 at offset 0x00000013ba6000 in file 'D:\CLCData\23_01_2013\CLC_LIS_Data.mdf'. Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.
When I select all data from the table, I got the error 1 at the above row position.
So, now I can't update or delete this row. Do you know this problem and how to fix it ?
Thank you very much,
Tai
|
|
|
|
|
Have you done what the error message suggested?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I checked the log error file. For the select query, I got the below error:
Error: 7886, Severity: 20, State: 1.
2014-07-14 11:27:01.50 spid52 A read operation on a large object failed while sending data to the client. A common cause for this is if the application is running in READ UNCOMMITTED isolation level. This connection will be terminated.
For the delete statement, I got the message:
Error: 824, Severity: 24, State: 2.
2014-07-14 13:34:10.12 spid51 SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0x4da7af2c; actual: 0xda5e9af7). It occurred during a read of page (1:40403) in database ID 6 at offset 0x00000013ba6000 in file 'D:\CLCData\23_01_2013\CLC_LIS_Data.mdf'. Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online
But, I don't know how to fix it.
|
|
|
|
|
Execute DBCC CHECKDB int SQL Server Management Studio, just like the error message tells you, then see what the results of the check are.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|