I need to fill a bit column only with 0 or 1, I tried the following, which only gave me 1:
convert(bit, 2*rand())
How can I make it work?
If you need multiple rows, and you don't care about the specific distribution of values, something like the following may be appropriate:
CONVERT(bit,SUBSTRING(CONVERT(binary(18),newid()),1,1)&1)
This will be evaluated once per row
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With