Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. problem of champ type

problem of champ type

Scheduled Pinned Locked Moved Database
helpdatabasetutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    foryou
    wrote on last edited by
    #1

    Hi I need to put 'abs' for students absent in a review for exemple of the material which the code is 121 . I have the following query:

    SELECT id_student, CASE WHEN (CODE) = 1 THEN 'Abs' ELSE [121] END AS m1,
    [122] AS '2', [123] AS '3'
    FROM (SELECT id_field, id_student, NOTE, CODE FROM TEST)
    p PIVOT (sum(NOTE) FOR id_field IN ([121], [122], [123])) AS pvt
    ORDER BY id_student

    I have the error here CASE WHEN (CODE) = 1 THEN 'Abs' because [121]is the type float and 'abs' is a text how to solve this? Thanks!!

    A 1 Reply Last reply
    0
    • F foryou

      Hi I need to put 'abs' for students absent in a review for exemple of the material which the code is 121 . I have the following query:

      SELECT id_student, CASE WHEN (CODE) = 1 THEN 'Abs' ELSE [121] END AS m1,
      [122] AS '2', [123] AS '3'
      FROM (SELECT id_field, id_student, NOTE, CODE FROM TEST)
      p PIVOT (sum(NOTE) FOR id_field IN ([121], [122], [123])) AS pvt
      ORDER BY id_student

      I have the error here CASE WHEN (CODE) = 1 THEN 'Abs' because [121]is the type float and 'abs' is a text how to solve this? Thanks!!

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Change your select to make 121 a char

      SELECT id_student, CASE WHEN (CODE) = 1 THEN 'Abs' ELSE '121' END AS m1

      or

      SELECT id_student, CASE WHEN (CODE) = 1 THEN 'Abs' ELSE convert(varchar,121) END AS m1

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      F 1 Reply Last reply
      0
      • A Ashfield

        Change your select to make 121 a char

        SELECT id_student, CASE WHEN (CODE) = 1 THEN 'Abs' ELSE '121' END AS m1

        or

        SELECT id_student, CASE WHEN (CODE) = 1 THEN 'Abs' ELSE convert(varchar,121) END AS m1

        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

        F Offline
        F Offline
        foryou
        wrote on last edited by
        #3

        Thank you very much Ashfield. but the problem is in 'abs' text in float champ :(.

        A 1 Reply Last reply
        0
        • F foryou

          Thank you very much Ashfield. but the problem is in 'abs' text in float champ :(.

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          I know, you want the literal value 'abs' or 121, so if you force your value 121 to become a char type, either by convert (or cast) or just by enclosing it in quotes then sql server will treat BOTH values as char types and will be quite happy (as far as I know). Try it and see, if it still doesn't work post your new code and the error message again.

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          F 1 Reply Last reply
          0
          • A Ashfield

            I know, you want the literal value 'abs' or 121, so if you force your value 121 to become a char type, either by convert (or cast) or just by enclosing it in quotes then sql server will treat BOTH values as char types and will be quite happy (as far as I know). Try it and see, if it still doesn't work post your new code and the error message again.

            Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

            F Offline
            F Offline
            foryou
            wrote on last edited by
            #5

            Thanks Ashfield!merci beaucoup i have anouther problem with this code ,I posted a new message. Thanks :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups