Hi, I am writing a stored procedure and want to copy some specific columns into another table. Here is the Code, it gives an error. Fields in table(interview): endclient, canid, timezone, interviewdate_5thrnd My Code: CREATE Procedure chkinterview AS BEGIN declare @curdt datetime, @dtadd datetime select @curdt=getdate() SELECT @dtadd=DATEADD(day,7, @curdt) IF EXISTS(SELECT * FROM interview WHERE interviewdate_5thrnd <> Cast('2/7/1900 12:00:00 AM' AS datetime)) BEGIN IF EXISTS(SELECT * FROM interview WHERE interviewdate_5thrnd <=@dtadd and interviewdate_5thrnd>=@curdt ) BEGIN insert into interview_dashboard values(endclient,canid,timezone,interviewdate_5thrnd) // (IS it the right way to the copy columns into another table) END END END Error:: The name "endclient" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. Thanks Pankaj Singh
Your insert statement is wrong... You have to use the values or variable in your INSERT statement... insert into interview_dashboard values(@endclient,@canid,@timezone,@interviewdate_5thrnd) or insert into interview_dashboard values('client name', 'canid' ,'timezone','interviewdate_5thrnd') Read the following... http://msdn.microsoft.com/en-us/library/aa933206(SQL.80).aspx
Try this if I interpret your query correctly. CREATE Procedure chkinterviewAS BEGINdeclare @curdt datetime,@dtadd datetime select @curdt=getdate()SELECT @dtadd=DATEADD(day,7, @curdt) INSERT INTO interview_dashboard (endclient,canid,timezone,interviewdate_5thrnd)SELECT endclient,canid,timezone,interviewdate_5thrndFROM interviewWHERE interviewdate_5thrnd <> Cast('2/7/1900 12:00:00 AM' AS datetimeAND interviewdate_5thrnd <=@dtadd and interviewdate_5thrnd>=@curdt NOTE: Change the interview_dashboard (?endclient,?canid,?timezone,?interviewdate_5thrnd) to whatever column name is in the interview_dashboard.