Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Error using openrowset

Author  Topic 

nitsmooth
Yak Posting Veteran

68 Posts

Posted - 2012-06-12 : 03:29:45
[code] EXEC('Insert Into #CountTable
FROM OPENROWSET
(''SQLOLEDB'',''DRIVER={SQL Server};SERVER=xxx;UID=uid;PWD=pwd'',
''Select '''''+@DateOfExecution+''''' ActivityDate, '+@Datacenter+' Datacenter, '+@Farmid+' Farm,DatePart(hh,Requestreceivedtime) [Hour],
Count(*) TotalTrans From DB01.dbo.'+ @Tablename + ' With (Nolock)
Where Requestreceivedtime Between '''''+@StartDate+''''' And '''''+@EndDate+'''''
And Status=1 Group by DatePart(hh,Requestreceivedtime)')
[/code]
Error Details:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'FROM'.
Msg 105, Level 15, State 1, Line 4
Unclosed quotation mark after the character string 'Select 'Jun 4 2012 12:00AM' ActivityDate, 3 Datacenter, 14 Farm,DatePart(hh,Requestreceivedtime) [Hour],
Count(*) TotalTrans From DB01.dbo.RequestQueue1014_568 With (Nolock)
Where Requestreceivedtime Between 'Jun 4 2012 12:00AM' And 'Jun 4 2012 11:59PM'
And Status=1 Group by DatePart(hh,Requestreceivedtime)'.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-12 : 15:14:05
change EXEC to PRINT,execute code and post the result here

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -