如何在sql里导出accpac中所有的数据库名和公司名
可以使用如下查询语句DECLARE @sysname sysname;
DECLARE @sql nvarchar(max);
DECLARE @sqlPrefix nvarchar(max);
DECLARE @sqlSuffix nvarchar(max);
SET @sql='';
SET @sqlPrefix='SELECT ORGID COLLATE DATABASE_DEFAULT AS ORGID, ' +
'CONAME COLLATE DATABASE_DEFAULT AS CONAME FROM';
SET @sqlSuffix='.dbo.CSCOM';
DECLARE My_Cursor CURSOR
FOR (select [name] from [master].[dbo].[sysdatabases])
OPEN My_Cursor;
FETCH NEXT FROM My_Cursor INTO @sysname;
WHILE @@FETCH_STATUS = 0
BEGIN
IF OBJECT_ID('[' + @sysname + '].dbo.CSCOM') IS NOT NULL
begin
if LTRIM(RTRIM(@sql))=''
begin
SET @sql = @sql + @sqlPrefix + ' [' + @sysname + ']' + @sqlSuffix + ' '+CHAR(10);
end
else
begin
SET @sql = @sql + 'UNION ALL' +CHAR(10) + @sqlPrefix + ' [' + @sysname + ']' + @sqlSuffix + ' '+CHAR(10);
end
end
FETCH NEXT FROM My_Cursor INTO @sysname;
END
PRINT @sql;
EXEC(@sql);
CLOSE My_Cursor;
DEALLOCATE My_Cursor;
GO
页:
[1]