# NewID()

**URL:** <https://forum.kirupa.com/t/newid/186000>\
**Category:** programming\
**Created:** [April 18, 2006, 10:59am UTC](https://forum.kirupa.com/t/newid/186000 "2006-04-18T10:59:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pucca](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@pucca](https://forum.kirupa.com/u/pucca)\
**Post date:** [April 18, 2006, 10:59am UTC](https://forum.kirupa.com/t/newid/186000/1 "2006-04-18T10:59:52Z")

</div>

I want to random select 5 records from my database… I got this code,

```
  Code:
 [LEFT]SELECT Top 5 * FROM comptbl ORDER BY NewID()[/LEFT]

```

but its gives me an error saying “[FONT=Arial][SIZE=2]Undefined function 'NewID() in expression.”  
What must I do? The site is done in asp… with a access database - if that helps?..

thanks for the help! [/SIZE][/FONT]:puzzled:

---

<div class="post-metadata">

**Author:** ![955](https://avatars.discourse-cdn.com/v4/letter/9/4bbf92/32.png) [@955](https://forum.kirupa.com/u/955)\
**Post date:** [April 18, 2006, 11:52am UTC](https://forum.kirupa.com/t/newid/186000/2 "2006-04-18T11:52:24Z")

</div>

Please don’t double post. Thanks.

I’ve never seen syntax like that in a SQL query…

---

<div class="post-metadata">

**Author:** ![teiz77](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/teiz77/32/771_2.png) [@teiz77](https://forum.kirupa.com/u/teiz77)\
**Post date:** [April 19, 2006, 7:16am UTC](https://forum.kirupa.com/t/newid/186000/3 "2006-04-19T07:16:30Z")

</div>

> [@pucca](#):
>
> I want to random select 5 records from my database… I got this code,
> 
> ```
> Code:
> [LEFT]SELECT Top 5 * FROM comptbl ORDER BY NewID()[/LEFT]
> 
> ```
> 
> but its gives me an error saying “[FONT=Arial][SIZE=2]Undefined function 'NewID() in expression.”  
> What must I do? The site is done in asp… with a access database - if that helps?..
> 
> thanks for the help! [/SIZE][/FONT]:puzzled:

NewId() only works on SQL server…

Try something like this:

```auto
<% 
    Randomize() 
    randNum = (CInt(1000 * Rnd) + 1) * -1 
 
    set conn = CreateObject("ADODB.Connection") 
 
    sql = "SELECT TOP 5 cols," & _ 
        "r = Rnd(" & randNum & ")" & _ 
        "FROM TableName " & _ 
        "ORDER BY r" 
 
    set rs = conn.execute(sql) 
 
    response.write rs(0) 
 
    ' ... 
    rs.close: set rs = nothing 
    conn.close: set conn = nothing 
%>

```
