SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Statment


SQL Statment

Author
Message
zero1de
zero1de
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 99
I need help to create the right SQL statment for my issue.
In the table are two different values separated by counter.

FIELDNR
- the Cardnr (021)
- the percent to Cardnr (022)

- PSNR is Personalnr from each Employee
- PFLFDNR is a seq. number for the fields 21 and 22 it show how many rows each Fieldnr already has

The values are identified with the help of the date field PFGLTFROM and PFGLTTO.
You must select of both records from a Personalnr always one active date out.

Example:

Rows for Persnr=64 and Cardnr=21 in different times (but we need only one record which is valid from and to date
FIRMA PSNR FIELDNR PFLFDNR VALUE PFGLTFROM PFGLTTO
1 64 021 1 2901009749 20110101 20140531
1 64 021 2 24 20140601 20321231
Rows for Persnr=64 and Cardnr=22 Percent in different times (but we need only one record which is valid from and to date
1 64 022 1 1 20110101 20120731
1 64 022 2 0 20120801 20120907
1 64 022 3 0.77 20120908 20120930
............................
1 64 022 10 1 20140816 20320101

I select the 2.row from Field=021 because it has the actual date PFGLTFROM=2014.06.01 PFGLTTO=2032.12.31
and the value from Fieldnr=22 is 1 because it has the actual date PFGLTFROM=20140816 PFGLTTO=20320101

This should be the Output
FIRMA PSNR FELDNR PFLFDNR Value1 Value2 PFGLTFROM PFGLTTO
1 64 021 2 24 1 20140601 20321231

I hope I could explain my problem Smile
Thx
zero1de
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search