﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / General / SQL Server 7,2000  / Insert statement not working - require scalar expression / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 16:32:19 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Insert statement not working - require scalar expression</title><link>http://www.sqlservercentral.com/Forums/Topic1074155-9-1.aspx</link><description>Thanks Lowell your example works,I also note the warning provided by SteveB.  I understand this and I am hoping this is just temporary until the company that support us can actually change the database structure.Cheers Guys for your speedy response.</description><pubDate>Mon, 07 Mar 2011 08:30:33 GMT</pubDate><dc:creator>wardy</dc:creator></item><item><title>RE: Insert statement not working - require scalar expression</title><link>http://www.sqlservercentral.com/Forums/Topic1074155-9-1.aspx</link><description>you will need to break the logic out into seperate steps1. define a variable to hold the value,  2. select the max(incomekey) into this variable.3. use this variable in your insert statementone issue you will have when using this approach for incrementing keys,  is that if two or more requests are happening at the same time there will be a possibility of dupliacate keys occuring.</description><pubDate>Mon, 07 Mar 2011 07:46:44 GMT</pubDate><dc:creator>steveb. </dc:creator></item><item><title>RE: Insert statement not working - require scalar expression</title><link>http://www.sqlservercentral.com/Forums/Topic1074155-9-1.aspx</link><description>the issue is to NOT use the INSERT...VALUES syntax, but INSERT...SELECTinstead:[code]insert into sbsincome (incomekey,flightkey) select   MAX(incomekey)+ 1 AS incomekey,    116040 AS flightkeyfrom sbsincome[/code]</description><pubDate>Mon, 07 Mar 2011 07:44:23 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>Insert statement not working - require scalar expression</title><link>http://www.sqlservercentral.com/Forums/Topic1074155-9-1.aspx</link><description>Hi, I am after a little help with an insert statement which is giving me an error of 'Subqueries are not allowed in this context.  Only scalar expressions are allowed.'I am not that clued up on scalar expressions and after hours of google search I am none the wiser.Bascialy I am trying to insert 2 column entries into a table, incomekey and flightkey.  However the income key field is defined as a char (8) not null, no auto increment has been built in.  so as a work around, I am trying to do a search to find the last used number in the field and add 1 to that value hence the select MAX statement[code="sql"]insert into sbsincome (incomekey,flightkey) values ((select MAX(incomekey)+1 from sbsincome),116040)[/code]If i just run the select statement without the insert it works fine.  How can I get the increment value to work on my insert statement?thank you in advance</description><pubDate>Mon, 07 Mar 2011 07:31:24 GMT</pubDate><dc:creator>wardy</dc:creator></item></channel></rss>