Results 1 to 22 of 22

Thread: equal sign not recognized

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    equal sign not recognized

    I have this query that works great in vb6, but I am rewriting it for .net 2010. In query builder it tells me that the = sign is not recognized.

    Code:
    SELECT DISTINCT Division, SUM(IIF(`Software Title`= 'MS Office Std', 1, 0)) AS StdProdist, 
    SUM(IIF(`Software Title`= 'MS Office Pro Plus', 1, 0)) AS ProProdist
    FROM `MS Office Licenses`
    Why does it work in vb6 but not .net 2010? Same database is being used, ms access. Same jet engine, or a version of the jet engine.

  2. #2
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: equal sign not recognized

    Have you tried using "LIKE" instead of the equal sign?
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: equal sign not recognized

    Wouldn't this be better?
    Code:
    SELECT Division, [Software Title], count(*)
    FROM [MS Office Licenses]
    GROUP BY Division, [Software Title]
    This is SQL server code, but I think all SQL variations have a group by clause.

    [edit] Using derived tables, not sure which databases support this
    Code:
    SELECT d1.Division,StdProdist,ProProdist
    FROM
    (SELECT Division,  count(*) as StdProdist
    FROM [MS Office Licenses]
    WHERE [Software Title] = 'MS Office Std') d1
    INNER JOIN
    (SELECT Division,  count(*) as ProProdist
    FROM [MS Office Licenses]
    WHERE [Software Title] = 'MS Office Pro Plus') d2 on d1.Divison = d2.Division
    [edit again] Judging from IIF, I assume you are using access, and I don't believe it supports derived tables. Can you post the .NET code?
    Last edited by wild_bill; Apr 21st, 2011 at 01:03 PM.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: equal sign not recognized

    Just the change of "bad fieldname" delimiters (from `` to [], eg: [Software Title] ) might be enough to solve it.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    Yes, I have tried "like", then it errors on like. Also I have tried a lot of things like [] `` single quotes and all cry about something in that line.

    wild_bill, I am trying to count each software title so I can get a total count across all divisions.

    I will try again tomorrow on using brackets. I had it like that from the beginning but was still erroring out on the equal sign.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    This is the exact query I am using and it still fails with the same error - Error in list of function arguments: '=' not recognized.
    Unable to parse query text.

    Code:
    SELECT DISTINCT Division, SUM(IIF([Software Title] = 'MS Office Std', 1, 0)) AS StdProdist, SUM(IIF([Software Title] = 'MS Office Pro Plus', 1, 0)) AS ProProdist
    FROM   [MS Office Licenses]
    WHERE  ((Version =  '2007') AND (Replacement = true))
    GROUP BY Division
    ORDER BY Division

  7. #7
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: equal sign not recognized

    What is the datatype of Replacement ?
    I guess the error is with Replacement = true
    thanks
    amrita

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    the datatype for replacement is yes/no so I suppose I could try yes instead of true. but in all reality it is a checkbox so true/false or yes/no should all be the same.

    nope, even using a 1 instead of true fails

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    Also, I can remove the replacement line and it still fails on = not recognized

  10. #10
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: equal sign not recognized

    Try this
    Code:
    Select Division,[Software Title], COUNT(*)
    FROM  [MS Office Licenses]
    WHERE WHERE  [Version] =  '2007' AND [Replacement] = true
    GROUP BY Division ,[Software Title]
    ORDER BY Division , [Software Title]
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    That works but the output is not what I wanted. I mean it does show the count per division, but not in a nice format. It shows the same division twice, one for each software title.

    Of course the editor changed it to Count(*) as Expr1

  12. #12
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: equal sign not recognized

    then try this:
    Code:
    SELECT DISTINCT Division, SUM(IIF([Software Title] = 'MS Office Std', 1, 0)) AS StdProdist, SUM(IIF([Software Title] = 'MS Office Pro Plus', 1, 0)) AS ProProdist
    FROM   [MS Office Licenses]
    WHERE  (([Version] =  '2007') AND ([Replacement] = true))
    GROUP BY Division
    ORDER BY Division
    Not sure about replacement but I would bet large sums of cash that Version is a reserved word.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    Nope, same error. I even took out Version and just left replacement and it still errored.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    So I am thinking that the version of Jet I am using doesn't allow IIF stuff when there is a equal sign in there.

    Funny as the version of Jet I was using in VB6 is the same version as what I am using in .NET 2010

    Anybody else have an idea?

  15. #15
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: equal sign not recognized

    To test your theory, try a little test:
    Code:
    SELECT IIF(1=1, 1, 0)
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    yes, it tells me the "=" is not recognized

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    So there is no way to do this? How stupid as it did work in vb6.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    I even tried this
    Code:
    SELECT DISTINCT 
                          Division, SUM(CASE [Software Title] WHEN 'MS Office Std' THEN 1 ELSE 0 END) AS StdProdist, 
                          SUM(CASE [Software Title] WHEN 'MS Office Pro Plus' THEN 1 ELSE 0 END) AS ProProdist
    FROM         [MS Office Licenses]
    WHERE     (Replacement = true)
    GROUP BY Division
    ORDER BY Division
    But it give a big error

    Error Message: IErrorInfo GetDescription failed with E_FAIL(0x80004005)

  19. #19
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: equal sign not recognized

    You could try creating that query in Access itself then just call that query in .Net 2010.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    How do you call the query in .NET from access?

  21. #21
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: equal sign not recognized

    I have tried recreating your scenario and it is odd that I cannot even create your query in Access itself. You are using an aggregate without grouping and Access is supposed to complain about that. This will work for me but not your code:

    Code:
    SELECT Sum([Division]) AS Expr1, SUM(IIF([Software Title]= 'test 2', 1, 0)) AS StdProdist, 
    SUM(IIF([Software Title]= 'test 2', 1, 0)) AS ProProdist
    FROM table1 GROUP BY  table1.[Software Title]
    And this even works in C# 2010:
    string test = "SELECT Sum([Division]), SUM(IIF([Software Title]= 'test 2', 1, 0)) AS StdProdist,SUM(IIF([Software Title]= 'test 2', 1, 0)) AS ProProdist FROM table1 GROUP BY table1.[Software Title]";

    Code:
    using (OleDbConnection connection = new OleDbConnection(@"PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PIS\Database1.mdb;"))
    {
        using (OleDbCommand command = new OleDbCommand(test, connection))
        {
            connection.Open();
    
            using (OleDbDataReader reader = command.ExecuteReader())
            {
                DataTable table = new DataTable();
    
                table.Load(reader);
    
                MessageBox.Show("ok");
                // The table can be used here to display the data.
                // That will most likely be done via data-binding but that is NOT a data access issue.
            }
        }
    }
    Did I miss anything?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: equal sign not recognized

    I tried that way in .NET and it doesn't give me errors yet it also doesn't get me any values.

    I have to think of how to do it a different way I guess.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width