get the records of the last day

Agustus 9, 2007

how to get the records of the last day of saveral months in SQL Server?

untuk yang tanggalnya range:
SELECT *
FROM <table>
WHERE <fieldDate> in
( select max(<fieldDateTwo>)
from <tableTwo>
where
<fieldDateTwo> between <@dateStart> And <@dateEnd>
group by year(
<fieldDateTwo>), month(<fieldDateTwo>)
)

untuk yg perTanggal:
declare @vOutputDate datetime
declare @pInputDate datetime
set @vOutputDate = cast(year(@pInputDate) as varchar(4)) + '/' + cast(month(@pInputDate) as varchar(2)) + '/01'
set @vOutputDate = dateadd(dd, -1, dateadd(m, 1, @vOutputDate))
select @vOutputDate

*tulisan ini saya buat sebagai pengingat untuk saya*
tapi mudah-mudahan jg berguna bagi yang lain🙂

3 Responses to “get the records of the last day”

  1. Luthfi Says:

    terlalu kecil tulisannya

    *mencet CTrl apa nyecroll*

  2. Luthfi Says:

    terlalu kecil tulisannya

    *mencet CTrl ama nyecroll*

  3. Luthfi Says:

    wah, kecatet 2
    hihihihihihi


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: