Stuff 0's between 2 int values

  • Hi all,

    declare @a int ,@b int,@c int

    set @a=1

    set @b-2=2

    Set @C=1002

    set @a=112

    set @b-2=2

    Set @C=112002

    I Need to stuff 0's between to int values.

    @C is the required o/p

    Thanks in advance

    Regard

    Guru

  • Hi,

    I do not know if I understand correctly but try this:

    Set @C = @a * 1000 + @b-2;

    Hope this helps.

  • This is a workaround to your requirement:

    declare @a varchar(10), @b-2 varchar(10), @C varchar(10), @d varchar(10) = '00'

    set @a='1'

    set @b-2='2'

    Set @C=+@a+@d+@b

    Select @C

    set @a=112

    set @b-2=2

    Set @C=+@a+@d+@b

    Select @C

    Hope this helps.

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

  • Thank you

    Vinu Vijayan

    Imoveis em Guarulhos

    Imoveis em Guarulhos its not working in some case..

    Vinu Vijayan data type is int only.

    Regards

    Guru

  • imex (4/27/2012)


    Hi,

    I do not know if I understand correctly but try this:

    Set @C = @a * 1000 + @b-2;

    Hope this helps.

    Yes. If you want "@c" to be calculated then you can use imex's method....or else if you want to stuff the 0s in between the variables you can use my method.

    This is a variation of my method when you can keep the variables as "int" and later cast them as varchar:

    declare @a int ,@b int,@c varchar(10), @d int = 0

    set @a=1

    set @b-2=2

    Set @C=+Cast(@a As varchar)+Cast(@d As varchar)+Cast(@d As varchar)+Cast(@b As varchar)

    Select @C

    set @a=112

    set @b-2=2

    Set @C=+Cast(@a As varchar)+Cast(@d As varchar)+Cast(@d As varchar)+Cast(@b As varchar)

    Select @C

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply