Fórum SQL - Datas #162924

27/05/2003

0

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

Responder

Posts

27/05/2003

Flavio Sanches

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???


Responder

Gostei + 0

27/05/2003

Karepa

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


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar