Update *

  • Experts,

    I have a table like,

    Table Name: Emp

    ENo Ename Age Level Stars

    1 AAAA 42 8 Null

    2 BBBB 38 6 Null

    3 CCCC 48 10 Null

    4 DDDD 32 5 Null

    5 EEEE 25 3 Null

    Now i want to update the Stars column like

    ENo Ename Age Level Stars

    1 AAAA 42 8 ********

    2 BBBB 38 6 ******

    3 CCCC 48 10 **********

    4 DDDD 32 5 *****

    5 EEEE 25 3 ***

    Stars column value = Values in the Level Column.

    for ex,If level is 8,then Stars column should contain 8 stars.

    Thanks in advance.

    karthik

  • Hi, you could use the REPLICATE function.

    E.g.:

    UPDATE [Emp]

    SET [Stars] = REPLICATE('*', [Level])

    Regards

  • Yes, you are correct.

    But,how to perform this one without REPLICATE function ?

    karthik

  • Well, you could use some sort of looping using cursors or CLR functions made using C# or so, but I do not see any advantage in not using REPLICATE.

  • karthikeyan (12/31/2007)


    Yes, you are correct.

    But,how to perform this one without REPLICATE function ?

    Why the restriction against replicate?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • My new RM asked me to provide the solution without REPLICATE function.

    Initially i used REPLICATE function.But he did not want to use REPLICATE.

    karthik

  • Did he give you a reason why? Sound a bit strange.

    Here's one that doesn't actually use replicate, but does the same thing as replicate would.

    DECLARE @Length INT

    SET @Length = 4

    SELECT REPLACE(SPACE(@Length),' ','*')

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Will this logic work out to update * in the star column ?

    karthik

  • Did you try it?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • It should, shouldn't it, if you just modify it a little to:

    UPDATE Emp

    SET [Level] = REPLACE(SPACE([Star])),' ','*')

  • Not yet. I will get back to you shortly.

    karthik

Viewing 11 posts - 1 through 10 (of 10 total)

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