Cint Equivalent ?!?!?!

Results 1 to 2 of 2

Thread: Cint Equivalent ?!?!?!

  1. #1
    Join Date
    Dec 1969

    Default Cint Equivalent ?!?!?!

    I&#039;m having a problem deleting a any given record. I&#039;ve got the algorithm figured out, but I&#039;m having a casting problem, can anyone help!?!?! please?!?!<BR><BR><BR>Details:<BR>I have a table that has a column called "my_field_name" <BR>it has values such as: &#039;some_value1&#039;, &#039;some_value2&#039;, &#039;some_value3&#039;, ... etc<BR><BR>All the records that are in the database have to be in chronological order (there HAS to be &#039;some_value2&#039; if a &#039;some_value3&#039; exists). <BR><BR>I encounter my problem after I delete my row and try to re-number anything that might be after it.<BR>Here&#039;s my sql code: <BR><BR>"UPDATE myTable<BR>SET my_field_name = &#039;some_value&#039; & (RIGHT(my_field_name, 1) - 1)<BR>WHERE type = 24 AND LEFT(my_field_name, 10) = &#039;some_value&#039;<BR> AND RIGHT(my_field_name, 1) &#062; 3"<BR><BR>my error is: "Syntax Error converting the varchar value &#039;some_value&#039; to a column of data type int."<BR>my_field_name is a varchar. and if I take the (RIGHT(my_field_name, 1) - 1)" out, it will work.<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Cint Equivalent ?!?!?!

    Declare @FirstVar nvarchar(10)<BR>Declare @SecondVar int<BR>Select @FirstVar = LEFT(some_value,LEN(some_value)-1)<BR>Select @SecondVar = CONVERT(INTEGER,RIGHT(some_value,1))<BR>Select @SecondVar =@SecondVar - 1<BR>Select @FirstVar = @FirsVar + @Secondvar<BR><BR>UPDATE myTable<BR>SET my_field_name = @Firstvar where.......<BR><BR>(since you&#039;re using SQL Server, why not wrap it in an Stored Proc??)<BR><BR>This might not be the most effiecient way, but it&#039;s the best I can come up with right now, also it&#039;s 100% untested, so you might need to tweak it a little bit. But something like this should do the trick.<BR><BR>(Brief explanation of the error: if you take only the left character of an varchar, that value will still be an varchar, so you have to do an explicit conversion)

Posting Permissions

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