You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sql-tools/查单.sql

107 lines
2.9 KiB

1 year ago
PRINT 'DECLARE @index int'
PRINT 'SELECT @index = 1;'
PRINT 'goto BeginTask'
PRINT 'RunTask:'
PRINT 'PRINT db_name() '
PRINT '--------------------------------------------- '
PRINT ''
PRINT ''
PRINT ''
PRINT '/*'
PRINT ' DECLARE @cmd varchar(1111) '
PRINT ' SELECT @cmd = ''osql -S(local) -Usa -P"S~a!i@D#a$o%8^8&0*6(0)6_3+" -d'' + db_name() + '' -iE:\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\update.sql'''
PRINT 'EXEC xp_cmdshell @cmd '
PRINT '*/'
PRINT '--------------------------------------------- '
PRINT 'SELECT @index = @index + 1'
PRINT 'BeginTask:'
DECLARE @database VARCHAR(200)
DECLARE @index int
SET @index = 1
DECLARE dbList cursor for
SELECT name
from master..sysdatabases
WHERE STATUS & 512 != 512
-- AND name IN
-- ( SELECT SUBSTRING(FConnectionString,
-- CHARINDEX('Initial Catalog=',FConnectionString) + LEN('Initial Catalog='),
-- CHARINDEX(';Integrated Security',FConnectionString) - (CHARINDEX('Initial Catalog=',FConnectionString) + LEN('Initial Catalog=')))
-- AS FDbName
-- FROM qd108.saidaodns.dbo.TClientServerConfig AS A,
-- qd108.saidaodns.dbo.TClientInfo AS C,
-- qd108.saidaodns.dbo.TServerInfo AS S
-- WHERE A.FClientId = C.FClientId
-- AND C.FServerId = S.FServerId
-- -- AND S.FHostId = 'qd11'
--)
OPEN dbList
FETCH dbList into @database
while @@FETCH_STATUS=0
BEGIN
DECLARE @CheckSql NVARCHAR(1000)
SELECT @CheckSql = 'SELECT @Biz = (SELECT count(1) FROM ' + @database + '..sysobjects WHERE name = ''TCompany'')'
DECLARE @biz BIT
EXEC sp_executesql @CheckSql,N'@biz BIT out ',@biz out;
SELECT @biz = 0 WHERE @biz IS NULL
IF @biz = 0
BEGIN
FETCH dbList into @database
CONTINUE
END
IF @Index = 1
BEGIN
PRINT 'IF @Index = ' + CAST(@Index AS VARCHAR(20))
END
ELSE
BEGIN
PRINT 'ELSE IF @Index = ' + CAST(@Index AS VARCHAR(20))
END
PRINT 'BEGIN'
PRINT ' use ' + @database
PRINT ' goto RunTask'
PRINT 'END'
DECLARE @sql VARCHAR(MAX)
EXEC ('use '+ @database +
'
IF object_id(''TConsumeBill'') IS NOT NULL AND NOT EXISTS(SELECT TOP 1 1 FROM TConsumeBill WHERE FBillTime > dateadd(d,-5,convert(varchar,getdate(),23)))
BEGIN
SELECT db_name()
END
')
--DECLARE @cmd VARCHAR(2000)
--SELECT @cmd = 'osql -S(local) -Usa -P"S~a!i@D#a$o%8^8&0*6(0)6_3+" -d' + @database + ' -iE:\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\update.sql'
--EXEC xp_cmdshell @cmd
PRINT ''
FETCH dbList INTO @database
SET @Index = @Index + 1
END
CLOSE dbList
DEALLOCATE dbList
PRINT 'PRINT ''END'''