Note that there are some explanatory texts on larger screens.

plurals
  1. POTemp Table giving Operand Clash error
    primarykey
    data
    text
    <p>I'm using a <code>CASE</code> statement to help populate a temp table, but for some reason I'm getting an Operand type clash error:</p> <pre><code>CREATE TABLE #users ( id INT IDENTITY (1, 1), userid UNIQUEIDENTIFIER, username VARCHAR(50), sysrole VARCHAR(50) ) --Insert all loadtest users into temp table INSERT INTO #users (userid, username, sysrole) SELECT id, username, sysrole = CASE WHEN id between 0 and 100 THEN '63F7971B-45FF-4E3C-86E7-9D0507AF60C0' WHEN id between 101 and 200 THEN '26478736-7937-4E52-891B-E80A8D609693' WHEN id between 201 and 300 THEN 'CEF5F44F-0961-414C-8578-22BEB0C4B9FF' WHEN id between 301 and 400 THEN '63F7971B-45FF-4E3C-86E7-9D0507AF60C0' WHEN id between 401 and 500 THEN '7FD13C9E-731B-43AE-95F0-E9AEDC65759C' END FROM user WHERE username LIKE '%Test%' </code></pre> <p>There are 500 users, so the CASE does handle all those possibilities. However the operand type clash is reading (on the line that the INSERT INTO begins on) <code>uniqueidentifier is incompatible with tinyint</code>.</p> <p>Is the <code>IDENTITY</code> column not autopopulating during the <code>INSERT</code>?</p> <p>EDIT: I just realized it would be useful to know what the <code>user</code> table looks like. It has about a dozen columns, but the ones I'm wanting to pull from it are:</p> <p><code>id</code> which is the primary key <code>username</code> which is a string (uniqueidentifier on user)</p> <p><code>sysrole</code> is getting defined by the <code>CASE</code> as you can see.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload