Results 1 to 7 of 7

Thread: Help on comparison problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    416

    Help on comparison problem

    Hi,

    I'm using ADO2.1 + SQL7 before, and everything is fine.
    Until now, SQL server is upgraded to SQL2K, and now I met a problem on field with "char" datatype.

    When inserting a value (e.g. "ABC") to a say char(5) field, sql2k will pad space to the field automatically, i.e. "ABC ".

    If running SQL, comparison is fine, but once I retrieve records from that table using ADO and compare the value w/rs,
    i.e.
    if rs("field1") = "ABC" then ...
    will return False now.

    I need to either change the statement to
    if trim(rs("field1")) = "ABC" then ...

    or change the type to varchar(5), but both are not good idea.

    Is there any method to solve this problem?

    Thx a lot!

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Why wouldn't Trim be a good idea? It would remove any additional spaces...

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    As I posted in the duplicate thread in the Databases forum,
    using the char(5) will take up more space in the database. using
    some other type like nvarchar(5) would be better.

    varchar: Variable-length character data type, length 0 to 8000 bytes.
    nvarchar: Unicode variable-length character data type.


    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    416
    Hi,

    Yes, I know the difference between char and varchar, but some old database was built using char and it don't need to trim() in those vb programs before the upgrade.

    Now I need to fix this problem, update program to trim() every field is impossible, and update char field to varchar is also cumbersome as there are many many fields in databases.

    So, I'm looking for any other better solutions.

    Thx!

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Kinda seems like your screwed either way, huh.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    Originally posted by stm
    Hi,

    Now I need to fix this problem, update program to trim() every field is impossible, and update char field to varchar is also cumbersome as there are many many fields in databases.

    So, I'm looking for any other better solutions.
    There are only two ways to go, there is no other way. Either u modify ur program or change DataType. Modifying program code will be painfull for u, so u have to choose a way that will be less painfull.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You could also write a small program to execute ALTER TABLE
    statements changing the filed types programmatically. Or shell
    out query analyzer passing it the statements to execute and
    pass the result message back to a file.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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