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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:32:32+00:00 2026-06-10T07:32:32+00:00

I managed to apply the PIVOT statement you suggested to transpose the values ​​of

  • 0

I managed to apply the PIVOT statement you suggested to transpose the values ​​of the records of a table as columns automatically:

DECLARE @PivotColumnas VARCHAR(MAX) 
SELECT    @PivotColumnas = COALESCE (@PivotColumnas + ',[' + IB_PDSBATCHATTRIBIDBI + ']', '[' + IB_PDSBATCHATTRIBIDBI + ']') FROM PDSBATCHATTRIB

DECLARE @PivotTablaSQL NVARCHAR(MAX)
 SET  @PivotTablaSQL = N' SELECT * 
FROM (SELECT INVENTBATCHID, ITEMID, PDSBATCHATTRIB.IB_PDSBATCHATTRIBIDBI, PDSBATCHATTRIBVALUE FROM PDSBATCHATTRIBUTES
  LEFT JOIN PDSBATCHATTRIB ON PDSBATCHATTRIBUTES.IB_PDSBATCHATTRIBIDBI = PDSBATCHATTRIB.IB_PDSBATCHATTRIBIDBI) AS TablaOrigen
 PIVOT
 (MIN(PDSBATCHATTRIBVALUE)
 FOR IB_PDSBATCHATTRIBIDBI IN ('+ @PivotColumnas + ')) AS PivotTable' 

EXECUTE (@PivotTablaSQL)

What I need is how to save the result as a query or create a table from this query. If I try to save the result as a query, I get the following error:

Incorrect syntax near the keyword ‘DECLARE’.

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-06-10T07:32:34+00:00Added an answer on June 10, 2026 at 7:32 am

    I found the solution, is very simple in fact!

    I only have to add the command INTO NewTable in the SELECT sentence oof the pivot table, just like that:

    SET  @PivotTablaSQL = N' SELECT * **INTO NewTable** 
    FROM (SELECT INVENTBATCHID, ITEMID, PDSBATCHATTRIB.IB_PDSBATCHATTRIBIDBI,   PDSBATCHATTRIBVALUE FROM PDSBATCHATTRIBUTES 
    LEFT JOIN PDSBATCHATTRIB ON PDSBATCHATTRIBUTES.IB_PDSBATCHATTRIBIDBI =  PDSBATCHATTRIB.IB_PDSBATCHATTRIBIDBI) AS TablaOrigen 
    PIVOT 
    (MIN(PDSBATCHATTRIBVALUE) 
    FOR IB_PDSBATCHATTRIBIDBI IN ('+ @PivotColumnas + ')) AS PivotTable' 
    

    This create a new table in the SQL database with the pivot table results.
    Thanks all!

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

Sidebar

Related Questions

I managed to apply this excellent example to my needs: http://code.google.com/p/galleriffic/issues/attachmentText?id=76&aid=-3045121742886940548&name=example-2.html&token=4nlvmgAfVpc5whcXC9UEqHZaSz0%3A1339257750721 With a small
is there a way how to apply the strikethrough style on a table cell
I want to apply sorting over Ajax, I managed to send the sort column
I am using the ListPicker from the toolkit. I have managed to apply a
I've successfully managed to connect to Apple's feedback APNS server but I'm not sure
I managed to set marker colors for individual markers { y: 5, marker: {
I managed to create a dynamic three dropdown list using Javascript code and it
I managed to request the publish_actions permission, but since it is revocable from the
I managed to found out how to delete field but I have a problem
The Managed Extensibility Framework (MEF) and Managed AddIn Framework (MAF, aka System.AddIn) seem to

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.