REPLICATE

  • Comments posted to this topic are about the item REPLICATE

  • This was removed by the editor as SPAM

  • good question. Thanks for sharing

  • Thanks for the nice easy question.

    Implicit conversion again - have there been a lot of those recently?

    Tom

  • O my God! How much coffee do i need today to recognize a hexa number?:-D

  • Had to resort to running some SQL for this one, as I don't carry the ascii table in my head 😉

  • Toreador (5/11/2016)


    Had to resort to running some SQL for this one, as I don't carry the ascii table in my head 😉

    Neither do I, but I do remember that 'A' is 0x41, that the lower case is 0x20 further up than upper case (so 'a' is 0x61) and 'e' is the 5th letter of the alphabet (so it's 0x65). That's probably a hangover from the days (more than 40 years ago) when I sometimes found myself needing to read a part of a of paper tape with my eyes instead of a machine.

    Life is so much easier these days when you can take a pen-drive to the pub at lunchtime and read it with your smartphone; a paper tape reader and a display device in the old days wouldn't fit into my pockets, or even into a large briefcase, so the human eye was the only thing available. Of course a paper tape reader back then didn't have a stack of invasive malware in its firmware, so the new technology has its minuses (malware everywhere) as well as its pluses (no need to use up brain space to remember an ascii table).

    Tom

  • I was, once again, looking for the trick because it seemed straightforward. Add me to the list of those who don't have the entire ASCII table in my head. Parts of it, but nowhere near all of it.

  • TomThomson (5/11/2016)


    Toreador (5/11/2016)


    Had to resort to running some SQL for this one, as I don't carry the ascii table in my head 😉

    Neither do I, but I do remember that 'A' is 0x41, that the lower case is 0x20 further up than upper case (so 'a' is 0x61) and 'e' is the 5th letter of the alphabet (so it's 0x65). That's probably a hangover from the days (more than 40 years ago) when I sometimes found myself needing to read a part of a of paper tape with my eyes instead of a machine.

    Life is so much easier these days when you can take a pen-drive to the pub at lunchtime and read it with your smartphone; a paper tape reader and a display device in the old days wouldn't fit into my pockets, or even into a large briefcase, so the human eye was the only thing available. Of course a paper tape reader back then didn't have a stack of invasive malware in its firmware, so the new technology has its minuses (malware everywhere) as well as its pluses (no need to use up brain space to remember an ascii table).

    Heh - It was also a lot harder to spread nasty things around back then. We didn't have the high-speed internet back then, much less the nice wireless networks of today. The number of devices has grown by who-knows-how-many orders of magnitude and it seems every one of them contains PII.

  • Haven't had to play with hex values in a long time.

  • Using a hex number was a 'trick'. 😛

    Glad I smelled a rat and didn't think "oh, ASCII 65 is an A" so I actually ran the code. It was then I recognized the value was 65 *hex* and not 65 decimal. (question was tackled pre-caffeine).

    At the risk of introducing real-world issues into an academic exercise I'd chew out somebody who used code like this:

    SELECT Replicate(0x65, 4)

    instead of:

    SELECT REPLICATE('e', 4)

    precisely because it's so easy to overlook it. This is exactly the kind of bug that can waste hours. If you insist on hex codes (why?) then use a well-commented variable as a pseudo-constant.

    I know the question was deliberately obfuscated, but I've been dealing with murky code a lot recently and just had to rant.

  • Iwas Bornready (5/11/2016)


    Haven't had to play with hex values in a long time.

    select convert(varchar(30), 0x5468616E6B20796F7520666F7220746865207175657374696F6E);

  • I had 2 problems with the documentation.

    1) It says you can use binary data but it doesn't give any examples of what happens when you use binary data.

    2) Under "Return Types" it says

    Returns the same type as string_expression.

    So it returns binary data? NO!!

  • Easy to confuse

    SELECT REPLICATE( 0x65, 4);

    with

    SELECT REPLICATE( CHAR(65), 4);

    At first glance 😀

  • Ed Wagner (5/11/2016)


    Iwas Bornready (5/11/2016)


    Haven't had to play with hex values in a long time.

    select convert(varchar(30), 0x5468616E6B20796F7520666F7220746865207175657374696F6E);

    Very cool.

Viewing 15 posts - 1 through 14 (of 14 total)

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