Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I tried:SELECT doc_no, seq_no, last_value(cus_no) over (partition by doc_no order by seq_no) as cus_Nofrom ARSRVFILI receive the message: "last_value is not a recognized built in function name"
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2013-10-09 : 12:21:48
Here is one way:
-- Sample dataDECLARE @Foo TABLE (doc_no INT, seq_no INT, cus_no VARCHAR(50))INSERT @Foo VALUES(1234, 0, 'ABC'),(1234, 1, NULL),(1234, 2, NULL),(4444, 0, 'XYZ'),(4444, 1, NULL)-- SelectSELECT f.doc_no, f.seq_no, t.cus_noFROM @Foo fINNER JOIN ( SELECT DISTINCT doc_no, cus_no FROM @Foo WHERE cus_no IS NOT NULL ) AS t ON f.doc_no = t.doc_no
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2013-10-09 : 12:59:37
if there will be only one NOT NULL value for cs_no in a group then this
SELECT doc_no,seq_no,MAX(cus_no) OVER (PARTITION BY doc_no) AS cus_noFROM Table
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs