Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:07:50+00:00 2026-05-11T07:07:50+00:00

I was looking at postgres question and it called for updating a table with

  • 0

I was looking at postgres question and it called for updating a table with random values.

I only noticed it was targeted at postgres after answering it, but in answering it I hit a mystery.

Here is my sample code in question:

create table #Buildings([Use] varchar(50), n int)  insert #Buildings select null,null from sysobjects   update #Buildings set [Use] =          case (ABS(CAST(CAST(NEWID() AS VARBINARY) AS int)) % 6)             when 0 then null             when 1 then 'warehouse'             when 2 then 'office'             when 3 then 'market'             when 4 then 'retail'             when 5 then 'workshop'             else 'HOW IS THIS POSSIBLE'         end,     n = ABS(CAST(CAST(NEWID() AS VARBINARY) AS int)) % 6  select [Use], count(*) from #Buildings group by [Use]   select n, count(*) from #Buildings group by n  

It returns a very odd result set:

Use                                                 -------------------------------------------------- ----------- workshop                                           128 HOW IS THIS POSSIBLE                               633 NULL                                               287 retail                                             140 warehouse                                          258 market                                             177 office                                             209 

And a second result set that makes complete sense:

n            ----------- ----------- 0           292 3           300 1           313 4           277 5           311 2           339 

The data for both result sets was generated in the same update statement.

So my question is why is a number out of the range of 0 – 5 hitting my case statement? What is that number? Why when I update the int directly is stuff distributed properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:07:50+00:00Added an answer on May 11, 2026 at 7:07 am

    I have an idea:

    maybe the value is being computed on every when statement, if it gets to the first one, computes a value other than 0 it goes to the second, it then computes a value other than 1, then the next and so on, if it makes it’s way to 5 and then computes a number other than 5 it goes to else.

    this would also explain why there are so many more ‘HOW IS THIS POSSIBLE’ than the others, the others are incremented when the current position and the random number generated at that position match.

    your thoughts?

    edit: also i’ve tested in sql server express 2008 and it’s the same outcome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 116k
  • Answers 116k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try $('#wrapper').css("height", newheight); May 11, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer Textarea: <textarea id="item" name="item" rows="5" cols="80">Some text in here</textarea> jQuery… May 11, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer It depends a bit on your version. Before 5.0.13 this… May 11, 2026 at 10:30 pm

Related Questions

I was looking at the API documentation for stl vector, and noticed there was
I was looking at http://tldp.org/LDP/abs/html/why-shell.html and was struck by: When not to use shell
I was looking at DataMapper , which appeared at first glance to use the
I was looking at WF and was wondering if it would be best to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.