none
Data Type Conversion RRS feed

  • Question

  • Hi all
    Am getting an error when converting a dataype Varchar into Bigint.
    My source variable is a varchar type and destination is bigint.
    Am using cast(var1 as bigint). Is this the right way to convert?
    Am using this in a join condition. 
    • Edited by SSDL Sunday, February 28, 2010 3:22 PM spelling check
    Sunday, February 28, 2010 3:21 PM

Answers

  • There you have it, text don't cast well into bigint. :-)
    A predicate in the WHERE clause might help you out to only recive those rows with numbers.
    Like this: WHERE (ISNUMERIC(var1) = 1)
    • Proposed as answer by Gerry Phillips Sunday, February 28, 2010 9:28 PM
    • Marked as answer by Zongqing Li Friday, March 5, 2010 7:43 AM
    Sunday, February 28, 2010 4:14 PM

All replies

  • Yes, that is one of the right ways to convert.
    You need to check out the value in var1 since it contains non numeric characters, thats why you get the error.
    Is var1 a variable or a column?
    Sunday, February 28, 2010 4:01 PM
  • thanks hakan. yes it a column
    Sunday, February 28, 2010 4:06 PM
  • the var1 contains text and sometimes numbers too
    Sunday, February 28, 2010 4:08 PM
  • There you have it, text don't cast well into bigint. :-)
    A predicate in the WHERE clause might help you out to only recive those rows with numbers.
    Like this: WHERE (ISNUMERIC(var1) = 1)
    • Proposed as answer by Gerry Phillips Sunday, February 28, 2010 9:28 PM
    • Marked as answer by Zongqing Li Friday, March 5, 2010 7:43 AM
    Sunday, February 28, 2010 4:14 PM