Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variable Database clause
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00762773
Message ID:
00762957
Vues:
15
You can switch database with USE command.
USE Reg
SELECT 	db.id, db.location_id, cs.name, db.total_due, db.check_num, db.check_date, cs.ssn,
	RTRIM(ISNULL(cs.address_1,' ') + ' ' + ISNULL(cs.address_2,' ')) address, cs.city,
	cs.state_id, cs.zip, cs.primary_phone, cs.secondary_phone, bk.name, db.routing_id,
	db.account_num, '' AS ref_name, '' AS ref_addr, '' AS ref_phone, db.status
 FROM  	AZ_dbo.debt db
 INNER JOIN AZ_dbo.debthistory dh ON dh.debt_id = db.id
 INNER JOIN AZ_dbo.deferred df ON df.debt_id = db.id
 INNER JOIN AZ_dbo.customer cs ON df.customer_id = cs.id
 INNER JOIN AZ_dbo.bank bk ON db.routing_id = bk.routing_id
 WHERE 	db.status = 'cor'
  AND  	dh.date between @StartDate AND CAST(@EndDate AS datetime) + ' 23:59:59.998'
  AND 	dh.type = 'sta'
  AND 	dh.description = 'Changed To: COR'
>The folowing select needs to run against 15 different databases (one for each region) on this server and 5 more on another server.
>
>
>SELECT db.id, db.location_id, cs.name, db.total_due, db.check_num, db.check_date, cs.ssn,
> RTRIM(ISNULL(cs.address_1,' ') + ' ' + ISNULL(cs.address_2,' ')) address, cs.city,
> cs.state_id, cs.zip, cs.primary_phone, cs.secondary_phone, bk.name, db.routing_id,
> db.account_num, '' AS ref_name, '' AS ref_addr, '' AS ref_phone, db.status
> FROM AZ_Reg..debt db
> INNER JOIN AZ_Reg..debthistory dh ON dh.debt_id = db.id
> INNER JOIN AZ_Reg..deferred df ON df.debt_id = db.id
> INNER JOIN AZ_Reg..customer cs ON df.customer_id = cs.id
> INNER JOIN AZ_Reg..bank bk ON db.routing_id = bk.routing_id
> WHERE db.status = 'cor'
> AND dh.date between @StartDate AND CAST(@EndDate AS datetime) + ' 23:59:59'
> AND dh.type = 'sta'
> AND dh.description = 'Changed To: COR'
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform