Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Select Data from table

Author  Topic 

zero1de
Posting Yak Master

105 Posts

Posted - 2014-07-26 : 16:01:16
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:
FIRMA PSNR FIELDNR PFLFDNR VALUE PFGLTFROM PFGLTTO
Rows for Persnr=64 and Cardnr=21 in different times (but we need only one record which is valid from and to date
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 9 0 20140714 20140815
1 64 022 10 1 20140816 20320101

Parameter: From and To Date

This should be the Output

Thx
zero1de
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
FIRMA PSNR FELDNR PFLFDNR Value1 Value2 PFGLTFROM PFGLTTO
1 64 021 2 24 1 20140601 20321231

I hope I could explain my problem :)
   

- Advertisement -