• run as a batch, i saw what you pasted was missing an open parenthesis, but otherwise just fine.

    i suspect it's a highlight-and-F5 issue.

    are you highlighting, say each section one part at a time,a dn when you run the code that is selected, it raises the error?

    for the code you pasted , ALL of the code must be highlighted and run together.

    --============Declare a couple variables=====================

    declare @prikey varchar(36);

    declare @lname varchar(60);

    --============Assign a variables a value==================

    set @prikey = (select cast (person_id AS varchar(36))

    from person

    where first_name = 'bob'

    and last_name = 'smith'

    );

    set @lname = (select last_name

    from person

    where first_name = 'bob'

    and last_name = 'smith'

    );

    --===============Use the variables======================

    create table #temp (x varchar(36) primary key, last_name varchar(60) )

    INSERT INTO #temp VALUES (@prikey, @lname)

    select * from #temp

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!