Questions tagged [newid]

NEWID() is a SQL Server function which creates a unique value of type uniqueidentifier.

NEWID() is a SQL Server function which creates a unique value of type uniqueidentifier.

Reference

MSDN article

73 questions
1
vote
3 answers

Sql Server 2005: Today's random records

I can easily get a random record with this: SELECT * FROM MyTable ORDER BY NewId() I can easily get a record with "today's date" with this: SELECT * FROM MyTable WHERE MyDate = "2010-24-08" -- db doesn't store times But how would I…
HelenJ
  • 139
  • 2
  • 5
1
vote
1 answer

NEWID() is generating the same value for all records in a relation

DECLARE @GUID uniqueidentifier SET @GUID = NEWID() INSERT INTO [MetaData Dummy].dbo.xxxx (someid, somename, LastUpdated, RecordSource) SELECT @GUID, TempCol, GETDATE(), xxx FROM AP_DevIDs Using the code above I am trying to insert a value into…
Bigtingz92
  • 129
  • 1
  • 15
1
vote
2 answers

Select row with mostly higher value and rarely lower value

I'm trying to select a random row from a table, but there is a column in this table called Rate, I want it to return the row that has a higher rate, and rarely ever return the rows that has a lower rate, is this possible? Table : CREATE TABLE…
Youssef
  • 50
  • 2
  • 9
1
vote
1 answer

Retrieve a random row with like statement (over 5 millions rows)

I have a DB with two tables tblVideos is about 8 million rows, contains Id(auto increment 1,1), videoId, Name, Tags, (FK)VideoProviderId tblVideoProviders is about 6 providers at the moment, and has 3 columns: Id(auto increment 1,1 tiny int), Name,…
Dima Vinogradov
  • 580
  • 4
  • 12
1
vote
2 answers

Order By VarBinary expression not sorted

While attempting to generate a seeded random ordering I noted this issue, now replicated both in SQL Server 2008 R2 (RTM) and on SEDE, i.e. SQL Server 2012 (SP1): When you ORDER BY a VarBinary sub-SELECT field the ordering does not occur. In the…
Mark Hurd
  • 10,665
  • 10
  • 68
  • 101
1
vote
1 answer

How to replace NEWID() in sql script file with an actual random Guid?

So I have a huge script file that will inset loads and loads of data into my database, here is a sample. INSERT INTO [dbo].[SysCountry] ([country_id], [country_name]) VALUES (NEWID(), 'Argentina'); INSERT INTO [dbo].[SysCountry] ([country_id],…
Ben
  • 187
  • 3
  • 12
1
vote
2 answers

Creating a Primary Key with NEWID()

I have a query that I used pull data from several different tables each night and this pull goes into an upsert table that is loaded to our cloud server. I am trying to set some type of unique identifer/primary key for each row, but I am having…
1
vote
1 answer

updating random dates to a single column (dates repeates)

Okay, first I identify the date integer for the particular date, onwards from which i need to update the random values into the dpm_dateto column : Query : select to_char(to_date('15/05/2013','dd/mm/yyyy'), 'J') from dual; Result: 2456428 Now, I…
1
vote
2 answers

Need to find a random record from one table, then join another table with this record

Background: I'm currently developing a simple online quiz. After the user has answered a simple question, the user gets the chance to improve their chances of winning by doing small tasks. Every lot the user earns is inserted into a separate row, so…
KlaasJan
  • 193
  • 2
  • 12
1
vote
1 answer

Update Random Sample in Large Table

Using SQL Server 2012, I have a table with 7 million rows. PK column is a GUID (COMB GUID). I am trying to test the performance of a query and first need to update a random sampling of data, I want to change a column value (not the PK) of 50,000…
Snowy
  • 5,942
  • 19
  • 65
  • 119
0
votes
1 answer

An ID number cannot be created in the database if it is auto generated by newid() InSqlserver with EF6

I created a column in a table named [Id] and made its type nvarchar(50), and its value is automatically by newid(), which is a mixture of letters and numbers, when adding a new record inside the database through a (sql server managment) , the new…
EBRAHEM
  • 15
  • 4
0
votes
2 answers

CTE Issues for Selecting Distinct Values and assigned NEWID() to those values

I'm having an issue with some CTE code I'm working with. My current goal is that I have a table that has a 'Type' column. I want to select all the DISTINCT types from that 'Type' column and, for each type, assign a value of NEWID() to a separate…
TripleCute
  • 71
  • 6
0
votes
1 answer

Trying to figure why NewID function stopped working on Oracle

I have used SELECT NEWID() FROM DUAL to generate new (random) guids in the past. However, today when tried I am getting the below Error: ORA-00904: "NEWID": invalid identifier I am not able to find this Particular Error by googling. So I guessed…
0
votes
2 answers

Getting issue in compute field for integer field in Odoo 13

i am getting issue when applying compute method(_compute_days) in integer field(days) for odoo 13. error is:- lead.age.audit(,).days my code is below:- class crm_lead_age(models.Model): _inherit = 'crm.lead' age_audit =…
Pawan Kumar Sharma
  • 1,168
  • 8
  • 30
0
votes
1 answer

RAND() function in sql server

Can anyone help me to understand how to use RAND() function in SQL Server? I have a scenario in which I want to fetch random products from products table in a random order on the basis of rating. Also, in this I want to give preference to higher…
Mohit
  • 3
  • 1