|
-
Oct 13th, 2004, 08:51 PM
#1
Thread Starter
Hyperactive Member
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!
-
Oct 13th, 2004, 09:29 PM
#2
Why wouldn't Trim be a good idea? It would remove any additional spaces...
-
Oct 13th, 2004, 10:22 PM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 13th, 2004, 10:43 PM
#4
Thread Starter
Hyperactive Member
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!
-
Oct 13th, 2004, 10:52 PM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 13th, 2004, 11:06 PM
#6
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.
-
Oct 13th, 2004, 11:51 PM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|