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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:01:24+00:00 2026-05-25T00:01:24+00:00

I’m using the SQL Server 2008 PIVOT function after I turn a CSV field

  • 0

I’m using the SQL Server 2008 PIVOT function after I turn a CSV field into a table using a UDF.

For the purpose of showing this error, I’m eliminating the first step which is CROSS APPLYing the CSV field to a UDF to get the table I’m manually creating in the code example below.

CREATE TABLE #TCMDRES (
    SYS_NR BIGINT,
    DAT_TE VARCHAR(150),
    ID CHAR(1)
)

-- ,,,,,,WIN ASDF v2,20100406.BAK,32515325772,32514331136,
-- After being separated and put into columns 1-11...
INSERT INTO #TCMDRES
VALUES(1,'','X'),(2,'','X'),(3,'','X'),(4,'','X'),(5,'','X'),(6,'','X'),(7,'WIN ASDF v2','X'),
(8,'20100406.BAK','X'),(9,'32515325772','X'),(10,'32514331136','X'),(11,'','X')

SELECT *
FROM #TCMDRES

-- This errors out with:
-- Msg 248, Level 16, State 1, Line 16
-- The conversion of the nvarchar value '32514331136' overflowed an int column.
SELECT ID, [8] AS FIL_NA, [10] AS FIL_SZ_NR
FROM
    (
    SELECT DAT_TE, SYS_NR, ID
    FROM #TCMDRES a 
    ) a
PIVOT (MAX(DAT_TE) FOR SYS_NR IN ([8],[10])) AS pvt
WHERE [10] <> 0

DELETE FROM #TCMDRES

-- Try again but drop the last two digits from column 10...
INSERT INTO #TCMDRES
VALUES(1,'','X'),(2,'','X'),(3,'','X'),(4,'','X'),(5,'','X'),(6,'','X'),(7,'WIN ASDF v2','X'),
(8,'20100406.BAK','X'),(9,'32515325772','X'),(10,'325143311','X'),(11,'','X')

SELECT ID, [8] AS FIL_NA, [10] AS FIL_SZ_NR
FROM
    (
    SELECT DAT_TE, SYS_NR, ID
    FROM #TCMDRES a 
    ) a
PIVOT (MAX(DAT_TE) FOR SYS_NR IN ([8],[10])) AS pvt
WHERE [10] <> 0

DROP TABLE #TCMDRES

To summarize, if you attempt to PIVOT on a large value even when it’s stored as a VARCHAR, it fails trying to convert it to an INT.

Does anyone have any ideas on how to fix this or if it’s fixable? Seems to be a limitation in the PIVOT function…

  • 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-25T00:01:25+00:00Added an answer on May 25, 2026 at 12:01 am

    It’s your WHERE clause. 0 is an INT. Try this (worked in testing for me):

    WHERE [10] <> CAST(0 as bigint)

    Alternatively, per Lamak:

    another way would be WHERE [10] <> '0'

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported

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.