Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

sp_MSforeachdb newbie trying to get query to run across 100+ databases.

$
0
0
Stumbled across the sp_MSForeachdb proc and thought I could use it for my problem. Trying to select off data sets across over 100 databases.. Thought this might work. however everything I've tried doesn't work. declare @fromDate datetimeset @fromDate = '2016-09-15 00:00:00.000'declare @toDate datetimeset @toDate = '2016-09-17 00:00:00.000'declare @command nvarchar(1000)Select @command ='SELECT PaymentNo, PaymentDate, TotalAmt from [PaymentHeader] WHERE Paymentdate between @fromDate AND @toDate'EXEC sp_MSforeachdb @command

Viewing all articles
Browse latest Browse all 3145

Trending Articles