Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:23:29+00:00 2026-06-09T20:23:29+00:00

I have a complex sql query given to me by my colleague. I want

  • 0

I have a complex sql query given to me by my colleague. I want to get one column in MMYYYY format. How can I achieve it? Following is the column part in query (the query is too long. so I am pasting only the column part).

CASE
   WHEN len(datepart (WEEK, cast(cast(month(from_date) AS VARCHAR(2)) + '/' + cast(xx.day_val AS VARCHAR(2)) + '/' + cast(year(from_date) AS VARCHAR(4)) AS DATETIME))) = 1 
   THEN '0' + datepart (WEEK, cast(cast(month(from_date) AS VARCHAR(2)) + '/' + cast(xx.day_val AS VARCHAR(2)) + '/' + cast(year(from_date) AS VARCHAR(4)) AS DATETIME))
   ELSE datepart (WEEK, cast(cast(month(from_date) AS VARCHAR(2)) + '/' + cast(xx.day_val AS VARCHAR(2)) + '/' + cast(year(from_date) AS VARCHAR(4)) AS DATETIME))
END AS week_number
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:23:30+00:00Added an answer on June 9, 2026 at 8:23 pm

    You can only retain date in specific format if you store the date as a string (char/varchar) not as datetime / date.

    To display date / datetime in a specific format, you need to use CONVERT or CAST:

    SELECT CONVERT(varchar,CONVERT(datetime, ‘2010-03’), 103)
    — 03/2010

    Reference: http://karaszi.com/the-ultimate-guide-to-the-datetime-datatypes (i hope that this will answer your question)

    Regards,

    Nicholas

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following somewhat complex sql query which has horrible performance, 'certainly' due to
I have this one gigantic complex LINQ to SQL query that I need to
I have a complex sql query that I have in a stored procedure and
I have a complex SQL Query, that needs to be filtered further. Part of
I have a very complex Linq to SQL query that returns a result set
I have this complex (to me) requirement and would appreciate a SQL query for
I am having issues with a sql query. I have following table (I simplified
I have a Complex SQL Query which is written with lot many Joins and
I have a complex query that joins different tables to get the count. There
I have a complex SQL query that joins multiple tables. Here's a watered down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.