locked
How do I use str function? RRS feed

  • Question

  • User-2023333290 posted

    Hi all,

    I have an update statement here:

    id is a long auto-increment integer.

    UPDATE [table1] SET [icon] = Str([id]) & @file_ext where id=@id;

    after I execute this statement, there is a space in my access, such as " 1.jpg"

    So I decide to hard-code the id:

    UPDATE [table1] SET [icon] = '1' & @file_ext where id=@id;

    It's work! the result is "1.jpg"

    Is there sth wrong in my code? Thx!

    Tuesday, April 6, 2010 1:05 PM

Answers

  • User188494879 posted

     try:

    UPDATE [table1] SET [icon] = TRIM(Str([id])) & @file_ext where id=@id;


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 6, 2010 1:40 PM

All replies

  • User188494879 posted

     try:

    UPDATE [table1] SET [icon] = TRIM(Str([id])) & @file_ext where id=@id;


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 6, 2010 1:40 PM
  • User-1199946673 posted

    Off course you could use trim, but I think you better do the string manipulation in .NET and not in SQL:

    UPDATE [table1] SET [icon] = @filename where id = @id

    in code behind:

    Dim id as Integer = 1
    Dim filename as String = id.ToString() + '.jpg'

    And use these values as the parameters

    Wednesday, April 7, 2010 5:09 AM
  • User-513735053 posted

    Follow karan@dotnet.

    UPDATE [table1] SET [icon] = TRIM(Str([id])) & @file_ext where id=@id;  

    it is rite.

    Wednesday, April 7, 2010 5:47 AM
  • User-966687016 posted

    Hi,

    try to use Trim function on Str([id]):

    UPDATE [table1] SET [icon] = LTRIM(RTRIM([YourString])) & @file_ext where id=@id;

    if T-SQL function TRIM does not exists

    if it is not working, check datatype of column Icon. If it is char, it will add some free spaces based on length of string and size of column.

    Regards

    Robert

    Wednesday, April 7, 2010 7:47 AM