SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Error using openrowset
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nitsmooth
Yak Posting Veteran

68 Posts

Posted - 06/12/2012 :  03:29:45  Show Profile  Reply with Quote
	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)')                                
	

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)'.

Edited by - nitsmooth on 06/12/2012 03:30:59

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 06/12/2012 :  15:14:05  Show Profile  Reply with Quote
change EXEC to PRINT,execute code and post the result here

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000