SQL - Datas

Delphi

27/05/2003

Olá,
Alguém sabe como escrevo um comando SQL para selecionar somente registros com mês = junho ( ou 06), independente de ano ??

Grato


Rikardo

Rikardo

Curtidas 0

Respostas

Flavio Sanches

Flavio Sanches

27/05/2003

no sql é assim:

SELECT ´Current Date´ = getdate()
go
Current Date
---------------------------
Feb 18 1995 11:46PM

SELECT ´Month Name´ = DATENAME(month, getdate())
go
Month Name
------------------------------
February

SELECT ´Month Number´ = DATEPART(month, getdate())
go
Month Number
------------
2

ou seja,
no seu caso:

select * from tabela
where DATEPART(month, data) = <numero do mes>

ou

select * from tabela
where DATENAME(month, data) = <nome do mes>


valeu???


GOSTEI 0
Karepa

Karepa

27/05/2003

em interbase / firebard.

select * from vendas where (select month from data) = 06

em SQL-SERVER / Oracle

select * from vendas where month(data) = 06

Deve funcionar


GOSTEI 0
POSTAR