SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Select Data from table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

zero1de
Yak Posting Veteran

Germany
77 Posts

Posted - 07/26/2014 :  16:01:16  Show Profile  Reply with Quote
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 :)

Edited by - zero1de on 07/27/2014 12:03:06
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000