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 6342175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:11:16+00:00 2026-05-24T20:11:16+00:00

SQL Server 2008r2 Express SP1. I need to make a sting with list of

  • 0

SQL Server 2008r2 Express SP1.
I need to make a sting with list of all distinct dates in some field for EXEC ‘dynamic SQL’. Of course, dates should be in right order. The code below works fine but my boss says that on big tables ORDER BY wouldn’t work in some cases because of @pivot_list =… in the SELECT statement. He has worked with SqlServer2000 and there this code even wouldn’t be compiled. Can anybody tell me whether this will work on SQL Server 2008r2?

USE tempdb
GO
DECLARE @pivot_list varchar(max)

CREATE TABLE #TovarSales(FullDate varchar(8))

INSERT #TovarSales VALUES ('20101010')
INSERT #TovarSales VALUES ('20101210')
INSERT #TovarSales VALUES ('20091010')
INSERT #TovarSales VALUES ('20111111')
INSERT #TovarSales VALUES ('20050505')

SELECT  @pivot_list = ISNULL(@pivot_list + ', ', '') + '[' + TS.FullDate + ']'
FROM #TovarSales TS
GROUP BY  TS.FullDate
ORDER BY TS.FullDate

select @pivot_list

DROP TABLE #TovarSales

Thanks.

  • 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-05-24T20:11:17+00:00Added an answer on May 24, 2026 at 8:11 pm

    This code DOES work in SQL Server 2008.

    The result is

     [20050505], [20091010], [20101010], [20101210], [20111111]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Server Version: SQL Server 2008R2 Client Version: SQL Server Express 2008R2 I have been
SQL Server 2005/2008 Express edition has the limitation of 4 GB per database. As
Sql Server 2008 R2 Express. NHibernate 2.1.2.4. I get SQL like: SELECT customer0_.Id as
When I tried upgrading from SQL Server 2008 R2 Express to SQL Server 2008
I have installed Visual Web Developer Express 2010, and SQL Server 2008 R2 Express
My company is working on a development project using SQL Server 2008 Express. The
I have a virtual windows server with SQL Server 2008 R2 Express. for the
I'm upsizing a Jet database to SQL Server Express 2008 R2 and before doing
I’m having a problem with a linked Informix table in MS SQL Server 2008r2.
I just ran an update edition to update from SQL Server 2008 R2 Express

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.