I need to make a query as follows, I have a table (script):
1 - Pick up the day of the week
2 - Get the server time in hh:mm
format
example:
SELECT
CASE DATEPART(DW, GETDATE())
WHEN 1 THEN 'DOMINGO'
WHEN 2 THEN 'SEGUNDA'
WHEN 3 THEN 'TERCA'
WHEN 4 THEN 'QUARTA'
WHEN 5 THEN 'QUINTA'
WHEN 6 THEN 'SEXTA'
WHEN 7 THEN 'SABADO'
END DIASEMANA,
CONVERT(VARCHAR(05),GETDATE(),108) AS 'HORA',
* FROM TB_ESTRACAO
where DIASEMANA = 'S'
Assemble a query this way:
select * from TB_ESTRACAO where HORA_FECHAMENTO > 'HORA' and 'DIASEMANA' = 'S'
USE [TESTE]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TB_ESTRACAO](
[IDEXTRACAO] [int] IDENTITY(1,1) NOT NULL,
[DESCRICAO] [varchar](100) NULL,
[HORA_FECHAMENTO] [char](10) NULL,
[PREMIACAO_MAXIMA] [int] NULL,
[SEGUNDA] [char](1) NULL,
[TERCA] [char](1) NULL,
[QUARTA] [char](1) NULL,
[QUINTA] [char](1) NULL,
[SEXTA] [char](1) NULL,
[SABADO] [char](1) NULL,
[DOMINGO] [char](1) NULL,
[STATUS] [char](1) NULL,
[MARCA] [char](1) NULL,
[DATA_INC] [datetime] NULL,
[DATA_HAB] [datetime] NULL,
[DATA_ALT] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[IDEXTRACAO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ((0)) FOR [PREMIACAO_MAXIMA]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [SEGUNDA]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [TERCA]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [QUARTA]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [QUINTA]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [SEXTA]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [SABADO]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [DOMINGO]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [STATUS]
GO
ALTER TABLE [dbo].[TB_ESTRACAO] ADD DEFAULT ('N') FOR [MARCA]
GO