Can I use the result of the Case clause as a field in Select?

Asked

Viewed 43 times

0

This question refers to this: How to return day of week and time formatted sql server 2008? I’m trying to fix it:

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'
  • This method may even work (but beware of the return of this datepart DW pq may vary depending on config. ) but place of formatting date is in front end. In user view even for maintenance and localization/globalization

  • Yes, there is no restriction of use in this case :)

  • @Marllonnasser, did you understand the question? I’m using the case result as a field in the table "Where DIASEMANA = ’S' ", this is not right.

  • but never that DIASEMANA will be = ’S'. You can filter straight from the DATEPART. where DATEPART(DW, GETDATE()) = 6

  • @Marllonnasser, in question I am referring to another question, where I have a table TB_ESTRACAO where in a column with the name of the day of the week, so I thought to use this way.

  • The issue has already been resolved, I posted my solution in the other question that has a link in this.

  • you doubled the question and answered the question itself. :|

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.