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. strange Sql Server error

strange Sql Server error

Scheduled Pinned Locked Moved Database
databaselearningsql-serversysadmintesting
6 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.
  • T Offline
    T Offline
    tiwal
    wrote on last edited by
    #1

    Hello . I am quite a beginner in Sql Server, I am testing some simple sql code on Sql Server 2012. I have a table called "AcctTransaction" composed by 4 columns :

    AccountId as Int,
    TransactionId as Int,
    TransactionDate as DateTime,
    Amount as Decimal (a8,4)

    I am trying to make this simple query work :

    SELECT AccountId
    ,SUM(Amount) OVER (PARTITION BY AccountId) AS FinalBalance
    ,SUM(Amount) OVER (PARTITION BY AccountId ORDER BY TransactionDate, TransactionId
    ) AS ProgressiveBalance
    FROM AcctTransaction

    I keep getting the following error :

    Incorrect syntax near "order" and in effect if I comment out the

    ,SUM(Amount) OVER (PARTITION BY AccountId ORDER BY TransactionDate, TransactionId ) AS ProgressiveBalance

    statement, everything works correctly. What's wrong with that statement ? I've made this query copying almost identically a sql statement I saw in a Microsoft course, where it seems to work perfectly.... Thanks to everyone who would answer ...

    T 1 Reply Last reply
    0
    • T tiwal

      Hello . I am quite a beginner in Sql Server, I am testing some simple sql code on Sql Server 2012. I have a table called "AcctTransaction" composed by 4 columns :

      AccountId as Int,
      TransactionId as Int,
      TransactionDate as DateTime,
      Amount as Decimal (a8,4)

      I am trying to make this simple query work :

      SELECT AccountId
      ,SUM(Amount) OVER (PARTITION BY AccountId) AS FinalBalance
      ,SUM(Amount) OVER (PARTITION BY AccountId ORDER BY TransactionDate, TransactionId
      ) AS ProgressiveBalance
      FROM AcctTransaction

      I keep getting the following error :

      Incorrect syntax near "order" and in effect if I comment out the

      ,SUM(Amount) OVER (PARTITION BY AccountId ORDER BY TransactionDate, TransactionId ) AS ProgressiveBalance

      statement, everything works correctly. What's wrong with that statement ? I've made this query copying almost identically a sql statement I saw in a Microsoft course, where it seems to work perfectly.... Thanks to everyone who would answer ...

      T Offline
      T Offline
      tiwal
      wrote on last edited by
      #2

      A sudden thought ... is it possibile that I am getting this error only because I am using the Express version of Sql Server 2012 ? Maybe the express version, being not complete, lacks the "LAG" function.... Just a random thought .....

      Richard DeemingR 1 Reply Last reply
      0
      • T tiwal

        A sudden thought ... is it possibile that I am getting this error only because I am using the Express version of Sql Server 2012 ? Maybe the express version, being not complete, lacks the "LAG" function.... Just a random thought .....

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        Are you sure you're using SQL 2012? I've just tried an equivalent query on my copy of 2012 Express, and it works perfectly.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        T 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          Are you sure you're using SQL 2012? I've just tried an equivalent query on my copy of 2012 Express, and it works perfectly.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          T Offline
          T Offline
          tiwal
          wrote on last edited by
          #4

          Well, that's what it says on "Help | About" section from the top menu .... Other infos are : Microsoft SQL Server Management Studio 11.0.2100.60 Microsoft Data Access Components (MDAC) 6.1.7601.17514 Microsoft MSXML 3.0 4.0 5.0 6.0 Microsoft Internet Explorer 9.11.9600.17801 Microsoft .NET Framework 4.0.30319.34209 Operating System 6.1.7601 Is it possible I have some components that's missing ?

          Richard DeemingR 1 Reply Last reply
          0
          • T tiwal

            Well, that's what it says on "Help | About" section from the top menu .... Other infos are : Microsoft SQL Server Management Studio 11.0.2100.60 Microsoft Data Access Components (MDAC) 6.1.7601.17514 Microsoft MSXML 3.0 4.0 5.0 6.0 Microsoft Internet Explorer 9.11.9600.17801 Microsoft .NET Framework 4.0.30319.34209 Operating System 6.1.7601 Is it possible I have some components that's missing ?

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            You might be using SQL 2012 Management Studio, but are you connecting to a SQL 2012 instance? Try running:

            SELECT @@VERSION


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            T 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              You might be using SQL 2012 Management Studio, but are you connecting to a SQL 2012 instance? Try running:

              SELECT @@VERSION


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              T Offline
              T Offline
              tiwal
              wrote on last edited by
              #6

              You are right my friend .... executing the query you suggested I realized I am actually using Sql Server 2008 .... and this maybe will solve some other problems I think I have ... Thank you very much

              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