sql 旧版混合SQL语句

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 旧版混合SQL语句相关的知识,希望对你有一定的参考价值。

select * from clientnumbers c,hend_ifds h where c.col001 = h.unitholderid and c.col001 <> '0' and col1 <> '999999'

update hend_ifds 
set NewClientRef = c.col003,
NewClientName = c.CLINAME
from clientnumbers c,hend_ifds h
where c.col001 = h.unitholderid and c.col001 <> '0' and col001 <> '999999'

CREATE PROCEDURE sp_rebuildindex
AS

	DECLARE @dbsid varbinary(85)

	SELECT  @dbsid = sid 
	FROM master.dbo.sysdatabases
    WHERE name = db_name()

	/*Check the user sysadmin*/
	 IF NOT is_srvrolemember('sysadmin') = 1 AND suser_sid() <> @dbsid
		BEGIN
			RAISERROR(15288,-1,-1,'SA or DBO','sp_rebuildindex')
			RETURN (1)
		END

	DECLARE @exec_stmt nvarchar(540)
	DECLARE @tablename sysname
	DECLARE @uid smallint
	DECLARE @user_name sysname
	DECLARE @tablename_header varchar(267)
	DECLARE tnames_cursor CURSOR FOR SELECT name, uid FROM sysobjects WHERE type = 'U' and status >=0
	OPEN tnames_cursor
	FETCH NEXT FROM tnames_cursor INTO @tablename, @uid
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN
			SELECT @user_name = user_name(@uid)
			SELECT @tablename_header = 'Rebuilding Indices on ' + @user_name + '.'+ RTRIM(LOWER(@tablename))
			PRINT @tablename_header
			SELECT @exec_stmt = 'DBCC DBREINDEX ("' + @user_name + '.' + @tablename + '")'
			EXEC (@exec_stmt)
		END
		FETCH NEXT FROM tnames_cursor INTO @tablename, @uid
	END
	PRINT ' '
	PRINT ' '
	PRINT 'All Indexes have been rebuilt'
	DEALLOCATE tnames_cursor
	RETURN(0) -- sp_rebuildindex

select 
 SUBSTRING(rtrim(substring(d.MAININDEX, charindex('~', d.MAININDEX) + 1, datalength(d.MAININDEX) - charindex('~', d.MAININDEX))),1, 30) as 'APPLICATION',
 d.DOCTYPE as 'Document Type',
 count(DISTINCT(d.DOCUMENTINDEX)) as 'Document Records',
 count(m.IMAGEPTR) as 'Image Records'
 from MF_PAGE m right join DOCUMENT d on m.DOCUMENTINDEX=d.DOCUMENTINDEX
 group by SUBSTRING(rtrim(substring(d.MAININDEX, charindex('~', d.MAININDEX) + 1, datalength(d.MAININDEX) - charindex('~', d.MAININDEX))),1, 30),
 d.DOCTYPE
 order by SUBSTRING(rtrim(substring(d.MAININDEX, charindex('~', d.MAININDEX) + 1, datalength(d.MAININDEX) - charindex('~', d.MAININDEX))),1, 30),
 d.DOCTYPE
select * from clientnumbers c,hend_ifds h where c.col001 = h.unitholderid and c.col001 <> '0' and col001 <> '999999'

update hend_ifds 
set NewClientRef = c.col003,
NewClientName = c.CLINAME
from clientnumbers c,hend_ifds h
where c.col001 = h.unitholderid and c.col001 <> '0' and col001 <> '999999'

select * from hend_ifds where newclientref<> ''

select * from clientnumbers where col001 = '595278'



select distinct(OBJECTID+'|'+IsNull(Worktype, ' ')+'|'+IsNull(CashAmount, ' ')+'|'+IsNull(ClientID, ' ')+'|'+IsNull(UnitHolderID, ' ')+'|'+IsNull(Idx3, ' ')+'|'+IsNull(Idx4, ' ')+'|'+IsNull(ObjectType, ' ')) from HEND_IFDS,[OUTPUT] where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0') and fullpath is null

select RTRIM(Newclientref)+'PE' from hend_ifds where newclientref is not null


select distinct
('APPEND PAGE|'+fullpath+'|'
+rtrim(IsNull(newclientref, ' '))+'PE|'
+rtrim(IsNull(newclientname, ' '))+'|20|'
+rtrim(IsNull(objecttype,' ')+'||'
+substring(shortdate,9,2)+'/'+substring(shortdate,6,2)+'/'+substring(shortdate,1,4)+'|'
+substring(shorttime,1,2)+':'+substring(shorttime,4,2)+':'+substring(shorttime,7,2)+'|||')
from HEND_IFDS 
where fullpath is not null and zerok is null and newclientref is not null

/* Query to report as a summary
*/
select custname, count(*) from Mortgage2Main1 group by custname
select barcode,count(*) from optika.cogentdocuments group by barcode having count(*) > 1
select c.barcode from optika.cogentdocuments c LEFT OUTER JOIN optika.objectlist o ON c.recid=o.recid where o.recid is null


select * from objectlist
select LEN(PurchaseOrderNo),count(*) from LUMAPIndex1 group by LEN(PurchaseOrderNo)

select PurchaseOrderNo from LUMAPIndex1 where PurchaseOrderNo  like '__[ ]__'

select PurchaseOrderNo,CHARINDEX(' ', PurchaseOrderNo) from LUMAPIndex1 where CHARINDEX(' ', PurchaseOrderNo) <>  LEN(PurchaseOrderNo)+1
select cliref,cliname,costctr,doctype,barcode,planman from cogentdocuments where  (cliref NOT LIKE '%[A-Z][A-Z]' AND cliref <> '*' and barcode <> '' and barcode <> '*' and barcode <> 'NO CODE')
/* Acorde input file for all uploadable objects - 456648 */

select distinct
('APPEND PAGE|'+fullpath+'|'
+rtrim(IsNull(newclientref, ' '))+'PE|'
+rtrim(IsNull(newclientname, ' '))+'|20|'
+rtrim(IsNull(objecttype,' '))+'||'
+substring(shortdate,9,2)+'/'+substring(shortdate,6,2)+'/'+substring(shortdate,1,4)+'|'
+substring(shorttime,1,2)+':'+substring(shorttime,4,2)+':'+substring(shorttime,7,2)+'|||')
 from HEND_IFDS 
where (fullpath is not null and newclientref <> '') and zerok is null
/* Acorde input file for all non-uploadable objects -  */

select distinct
('APPEND PAGE|'+fullpath+'|'
+rtrim(IsNull(newclientref, ' '))+'PE|'
+rtrim(IsNull(newclientname, ' '))+'|20|'
+rtrim(IsNull(objecttype,' '))+'||'
+substring(shortdate,9,2)+'/'+substring(shortdate,6,2)+'/'+substring(shortdate,1,4)+'|'
+substring(shorttime,1,2)+':'+substring(shorttime,4,2)+':'+substring(shorttime,7,2)+'|||')
 from HEND_IFDS 
where (fullpath is null or newclientref = '') or zerok is not null
select count(*) from oracleapmain1
select sum(pagecount) from oracleapmain1
select count(*) from acpmain1
select sum(pagecount) from acpmain1

--docs & pages in oracleapmain1 between 1st Jan 2001 & 31st Dec 2007
select count(*) from oracleapmain1
where invdate > '31 Dec 2000'
AND invdate < '01 Jan 2008'
select sum(pagecount) from oracleapmain1
where invdate > '31 Dec 2000'
AND invdate < '01 Jan 2008'

--docs & pages in oracleapmain1 greater that 31 Dec 2007
select count(*) from oracleapmain1
where invdate > '31 Dec 2007'
select sum(pagecount) from oracleapmain1
where invdate > '31 Dec 2007'

--docs & pages in acpmain1 between 1st Jan 2001 & 31st Dec 2007
select count(*) from acpmain1
where invdate > '31 Dec 2000'
AND invdate < '01 Jan 2008'
select sum(pagecount) from acpmain1
where invdate > '31 Dec 2000'
AND invdate < '01 Jan 2008'

--docs & pages in acpmain1 greater that 31 Dec 2007
select count(*) from acpmain1
where invdate > '31 Dec 2007'
select sum(pagecount) from acpmain1
where invdate > '31 Dec 2007'


--1000 oracleapmain1 document details between 1st Jan 2001 & 31st Dec 2007
select *, datepart(d, invdate), datepart(m, invdate), datepart(yy, invdate) 
from oracleapmain1
where invdate > '31 Dec 2000'
AND invdate < '01 Jan 2008'
order by invdate


--acpmain1 document details between 1st Jan 2001 & 31st Dec 2007
select *, datepart(d, invdate), datepart(m, invdate), datepart(yy, invdate) 
from acpmain1
where invdate > '31 Dec 2000'
AND invdate < '01 Jan 2008'
order by invdate


--oracleapmain1 invoices with bad date of 01 Jan 1900
select * from oracleapmain1
where invdate = '01 Jan 1900'
--acpmain1 invoices with bad date of 01 Jan 1900
select * from acpmain1
where invdate = '01 Jan 1900'




sp_help oracleapmain1
SELECT NEWCLIENTREF FROM
HEND_IFDS A,CLIENTNUMBERS B
WHERE
B.COL001 = A.UNITHOLDERID AND
A.NEWCLIENTREF = 'HGI99999'



UPDATE HEND_IFDS
SET NEWCLIENTREF = 'IFDS'+B.COL002
FROM HEND_IFDS A,CLIENTNUMBERS B
WHERE
B.COL001 = A.UNITHOLDERID AND
A.NEWCLIENTREF = 'HGI99999'
/* Update doccount to the actual number of attachments
JRHC (HRH)
31/10/2001
*/
create procedure update_doccount
as
create table #u_counts(pkgid int primary key,y int)

insert into #u_counts select pkgid,count(*) from wf_pkgattachment group by pkgid

UPDATE WFUSER.WF_FieldValue_3
SET COL6 = #U_COUNTS.Y 
FROM WFUSER.WF_FieldValue_3, #u_counts
WHERE WFUSER.WF_FieldValue_3.pkgid = #u_counts.pkgid

UPDATE WFUSER.WF_FieldValue_3
SET COL6 = COL6 - 1
Where COL6 > 1
go
select distinct(OBJECTID+' '+IsNull(Worktype, ' ')+' '+IsNull(CashAmount, ' ')+' '+IsNull(ClientID, ' ')+' '+IsNull(UnitHolderID, ' ')+' '+IsNull(Idx3, ' ')+' '+IsNull(Idx4, ' ')+' '+IsNull(ObjectType, ' ')) from HEND_IFDS where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0') and fullpath is not null 

select distinct(ClientID) from HEND_IFDS where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0') and fullpath is not null  ORDER BY CLIENTID

select DISTINCT(UNITHOLDERID)  from HEND_IFDS where fullpath is not null AND  UNITHOLDERID <>'0'
//* The below query will highlight .share client entries that do not match up 
with the clients in the maximizer database*//

select * from zeus.redcarpet.hrhuser.app1 where fld1 not in (select distinct name from client)



update hrhuser.app1 set fld1 = '' where fld1 = ''
SET NOCOUNT ON
   DECLARE @LogicalFileName sysname,
           @MaxMinutes INT,
           @NewSize INT

   -- *** MAKE SURE TO CHANGE THE NEXT 4 LINES WITH YOUR CRITERIA. ***
   USE     [?????]              -- This is the name of the database
                                  -- for which the log will be shrunk.
   SELECT  @LogicalFileName = '?????',  -- Use sp_helpfile to 
      -- identify the logical file 
      -- name that you want to shrink.
           @MaxMinutes = ?????,      -- Limit on time allowed to wrap log.
           @NewSize    = ?????       -- in MB

   -- Setup / initialize
   DECLARE @OriginalSize int
   SELECT @OriginalSize = size -- in 8K pages
     FROM sysfiles
     WHERE name = @LogicalFileName
   SELECT 'Original Size of ' + db_name() + ' LOG is ' + 
           CONVERT(VARCHAR(30),@OriginalSize) + ' 8K pages or ' + 
           CONVERT(VARCHAR(30),(@OriginalSize*8/1024)) + 'MB'
     FROM sysfiles
     WHERE name = @LogicalFileName

   CREATE TABLE DummyTrans
     (DummyColumn char (8000) not null)

   -- Wrap log and truncate it.
   DECLARE @Counter   INT,
           @StartTime DATETIME,
           @TruncLog  VARCHAR(255)
   SELECT  @StartTime = GETDATE(),
           @TruncLog = 'BACKUP LOG ['+ db_name() + '] WITH TRUNCATE_ONLY'
   -- Try an initial shrink.
   DBCC SHRINKFILE (@LogicalFileName, @NewSize)

   EXEC (@TruncLog)

   -- Wrap the log if necessary.
   WHILE     @MaxMinutes > DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired
         AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName)  -- the log has not shrunk    
         AND (@OriginalSize * 8 /1024) > @NewSize  -- The value passed in for new size is smaller than the current size.
     BEGIN -- Outer loop.
       SELECT @Counter = 0
       WHILE  ((@Counter < @OriginalSize / 16) AND (@Counter < 50000))
         BEGIN -- update
           INSERT DummyTrans VALUES ('Fill Log')  -- Because it is a char field it inserts 8000 bytes.
           DELETE DummyTrans
           SELECT @Counter = @Counter + 1
         END   -- update
       EXEC (@TruncLog)  -- See if a trunc of the log shrinks it.
     END   -- outer loop
   SELECT 'Final Size of ' + db_name() + ' LOG is ' +
           CONVERT(VARCHAR(30),size) + ' 8K pages or ' + 
           CONVERT(VARCHAR(30),(size*8/1024)) + 'MB'
     FROM sysfiles 
     WHERE name = @LogicalFileName
   DROP TABLE DummyTrans
   PRINT '*** Perform a full database backup ***'
   SET NOCOUNT OFF
SELECT     'EXPORT|*****|GARTMORE|CliRef', RTRIM(CliRef), 'CliName', RTRIM(CliName), 'CostCtr', RTRIM(CostCtr), 'DocType', RTRIM(DocType), 'DocDate', DateName(dd, DocDate) + '/' + Convert(varchar(2), DatePart(m, DocDate)) + '/' + DateName(yyyy, DocDate), 'ArchDate', DateName(dd, ArchDate) + '/' + Convert(varchar(2), DatePart(m, ArchDate)) + '/' + DateName(yyyy, ArchDate), 'ArchTime', RTRIM(ArchTime), 'Barcode', RTRIM(Barcode), 'PlanMan', RTRIM(PlanMan), 'EOFLD|-1|AllPages|NA|NA|NoMatchOK|AnnotsYes|9|NATIVE|D:\Optika\Acorde\Transact\Test\'+ RTRIM(RECID), 'GV|NA|NA|NA|NA|EOFLD|*****'
FROM         context.CogentDocuments
WHERE     (CostCtr = '30') AND (CliRef LIKE '%PE') OR
                      (CostCtr = '35') AND (CliRef LIKE '%PE') OR
                      (CostCtr = '53') AND (CliRef LIKE '%BA')
ORDER BY ArchDate
select * from optika.cogentdocuments

select * from ACORDELIVE.emedia.optika.cogentdocuments A, Optika.cogentdocuments B
where B.barcode = A.barcode

select * from ACORDELIVE.emedia.optika.cogentdocuments A, Optika.cogentdocuments B
where B.barcode <> A.barcode

update optika.cogentdocuments
set cliref = A.cliref, cliname = A.cliname, costctr = A.costctr, doctype = A.doctype, docdate = A.docdate
from ACORDELIVE.emedia.optika.cogentdocuments A, Optika.cogentdocuments B
where B.barcode = A.barcode

select * from optika.cogentdocuments
where cliref = '*'
select @@version

SELECT   SERVERPROPERTY('productversion') as productversion, SERVERPROPERTY('productlevel') as productlevel, SERVERPROPERTY('edition') as edition
select count(*),fld1,fld2,fld3,fld4,fld5,fld6,fld7,fld8,fld9
from app1
group by fld1,fld2,fld3,fld4,fld5,fld6,fld7,fld8,fld9
having count(*) > 1
COMPUTE sum(COUNT(*))
/* Count of Total rows that 'should' be uploadable - 516862 */

select count(distinct(
'APPEND PAGE|'+fullpath+'|'
+rtrim(IsNull(newclientref, ''))+'PE|'
+rtrim(IsNull(newclientname, ''))+'|20|'
+rtrim(IsNull(objecttype,''))+'||'
+substring(shortdate,9,2)+'/'+substring(shortdate,6,2)+'/'+substring(shortdate,1,4)+'|'
+substring(shorttime,1,2)+':'+substring(shorttime,4,2)+':'+substring(shorttime,7,2)+'|||'))
 from HEND_IFDS 

/* Acorde input file for all uploadable objects - 456648 */

select distinct(
'APPEND PAGE|'+fullpath+'|'
+rtrim(IsNull(newclientref, ''))+'PE|'
+rtrim(IsNull(newclientname, ''))+'|20|'
+rtrim(IsNull(objecttype,''))+'||'
+substring(shortdate,9,2)+'/'+substring(shortdate,6,2)+'/'+substring(shortdate,1,4)+'|'
+substring(shorttime,1,2)+':'+substring(shorttime,4,2)+':'+substring(shorttime,7,2)+'|||')
 from HEND_IFDS 
where isnull(fullpath, '') <> ''
and isnull(newclientref, '') <> ''
and isnull(zerok, '') <> 'Y'

/* Acorde input file for all non-uploadable objects - 60214 */

select distinct(
'APPEND PAGE|'+fullpath+'|'
+rtrim(IsNull(newclientref, ''))+'PE|'
+rtrim(IsNull(newclientname, ''))+'|20|'
+rtrim(IsNull(objecttype,''))+'||'
+substring(shortdate,9,2)+'/'+substring(shortdate,6,2)+'/'+substring(shortdate,1,4)+'|'
+substring(shorttime,1,2)+':'+substring(shorttime,4,2)+':'+substring(shorttime,7,2)+'|||')
 from HEND_IFDS 
where isnull(fullpath, '') = ''
or isnull(newclientref, '') = ''
or isnull(zerok, '') = 'Y'







/* where not ((fullpath is not null and newclientref <> '') and zerok is null)

Select count(*)
from hend_ifds

Select Distinct FullPath, NewClientRef, NewClientName, ObjectType
from hend_ifds
where isnull(fullpath, '') <> ''
and isnull(newclientref, '') <> ''
and isnull(zerok, '') <> 'Y'

Select Distinct FullPath, NewClientRef, NewClientName, ObjectType
from hend_ifds
where isnull(fullpath, '') = ''
or isnull(newclientref, '') = ''
or isnull(zerok, '') = 'Y'

Select FullPath, NewClientRef, NewClientName, ObjectType, Count(*)
from hend_ifds
Group By FullPath, NewClientRef, NewClientName, ObjectType
Compute Sum(Count(*))

Select (1809951 - 434872) - 61639



Select count(Distinct fullpath, newclientref, newclientname, objecttype, shortdate, shorttime)
from hend_ifds

Select count(Distinct fullpath, newclientref, newclientname, objecttype, shortdate, shorttime)
from hend_ifds
where (fullpath is not null and IsNull(newclientref, '') <> '') and zerok is null

Select count(Distinct fullpath + newclientref + newclientname + objecttype + shortdate + shorttime)
from hend_ifds
where not ((fullpath is not null and newclientref <> '') and zerok is null)

Select count(Distinct fullpath + newclientref + newclientname + objecttype + shortdate + shorttime)
from hend_ifds
where not ((fullpath is not null and IsNull(newclientref, '') <> '') and zerok is null)

*/
DROP table #RJATEMP
go

create table #RJATEMP 
( recid   	int,
  pagecount	int
)
go

Insert #RJATEMP
select recid,count(*) from objectlist group by recid order by recid
go

select * FROM
objectlist O,#rjatemp R
where o.recid = r.recid and o.pagecount <> r.pagecount
go

/*
update objectlist
set pagecount = R.pagecount
FROM
objectlist O,#rjatemp R
where o.recid = r.recid and o.pagecount <> r.pagecount
*/

select * from
applicationtable A,#rjatemp R
where A.recid = r.recid and A.pagecount <> r.pagecount
go


/*
Identifying page sequencing problem within objectlist

select * FROM
optika.objectlist o,#rjatemp R
where o.recid = r.recid and o.sequence > r.pagecount
order by o.recid
go
*/
/*
 NAME: NOPAGES.SQL
 Written by: JCR - 26/06/2002
-----------------------------
 This query will return the count of number of documents without pages in a MULTI database.
 The criteria is an entry in the DOCUMENT table with no corresponding entry in MF_PAGE.
 This is achieved by a LEFT JOIN.
 Although there is a one-to-many relationship between DOCUMENT and MF_PAGE, 
 since we are looking for the absence of a row in MF_PAGE we do not require the 'DISTINCT' keyword to give an accurate count.
*/

SELECT count(DOCUMENT.DOCUMENTINDEX)
FROM DOCUMENT LEFT JOIN MF_PAGE ON DOCUMENT.DOCUMENTINDEX = MF_PAGE.DOCUMENTINDEX
WHERE (((MF_PAGE.DOCUMENTINDEX) Is Null))
Select RegNumber, Count(*)
From Installers
Group By RegNumber
Having Count(*) >= 2
select count(*) from npi_gdeals

SELECT
'APPEND PAGE|'
+OBJECTLOCATION+'|'
+ISNULL(MF1, '')+'|'
+SUBSTRING(ISNULL(MF2, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(MF2, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(MF2, '1900-01-01'),1,4)+'|'
+SUBSTRING(ISNULL(SF2, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF2, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF2, '1900-01-01'),1,4)+'|'
+SUBSTRING(ISNULL(SF3, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),1,4)+'|'
+SFNAME+'|'
FROM NPI_GDEALS

SELECT
'APPEND PAGE|'
+OBJECTLOCATION+'|'
+ISNULL(MF1, '')+'|'
+SUBSTRING(ISNULL(MF2, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(MF2, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(MF2, '1900-01-01'),1,4)+'|'
+SUBSTRING(ISNULL(SF2, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF2, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF2, '1900-01-01'),1,4)+'|'
+SUBSTRING(ISNULL(SF3, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),1,4)+'|'
+SFNAME+'|',
datalength ('APPEND PAGE|'
+OBJECTLOCATION+'|'
+ISNULL(MF1, '')+'|'
+SUBSTRING(ISNULL(MF2, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(MF2, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(MF2, '1900-01-01'),1,4)+'|'
+SUBSTRING(ISNULL(SF2, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF2, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF2, '1900-01-01'),1,4)+'|'
+SUBSTRING(ISNULL(SF3, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),1,4)+'|'
+SFNAME+'|') as length
FROM NPI_GDEALS
ORDER by length

/* Acorde input file for all uploadable objects - 18837 LEGALS - APPLICATION FORMS */

SELECT * FROM NPI_LEGALS WHERE SFNAME = 'APPLICATION FORMS'

SELECT
'APPEND PAGE|'+OBJECTLOCATION+'|'
+NEWCLIENTNO+'PE|'
+NEWCLIENTNAME+'|75|'
+SFNAME+'|'
+SUBSTRING(ISNULL(SF2, '01-01-1900'),1,2)+'/'+SUBSTRING(ISNULL(SF2, '01-01-1900'),4,2)+'/'+SUBSTRING(ISNULL(SF2, '01-01-1900'),7,4)+'|'
+SUBSTRING(ISNULL(SF3, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),1,4)
+'||||'
FROM NPI_LEGALS
WHERE NEWCLIENTNO <> 'BLANK'
AND SFNAME = 'APPLICATION FORMS'

/* Acorde input file for all uploadable objects - 0 LEGALS - AUTHORISED SIGNATORIES */

SELECT * FROM NPI_LEGALS WHERE SFNAME = 'AUTHORISED SIGNATORIES'

SELECT
'APPEND PAGE|'+OBJECTLOCATION+'|'
+ISNULL(NEWCLIENTNO, '')+'PE|'
+ISNULL(NEWCLIENTNAME, '')+'|75|'
+ISNULL(SFNAME, '')+'|'
+SUBSTRING(ISNULL(SF2, '01-01-1900'),1,2)+'/'+SUBSTRING(ISNULL(SF2, '01-01-1900'),4,2)+'/'+SUBSTRING(ISNULL(SF2, '01-01-1900'),7,4)+'|'
+SUBSTRING(ISNULL(SF3, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),1,4)
+'||||'
FROM NPI_LEGALS
WHERE ISNULL(NEWCLIENTNO, '') <> 'BLANK'
AND ISNULL(SFNAME, '') = 'AUTHORISED SIGNATORIES'

/* Acorde input file for all uploadable objects - 2294 LEGALS - CHANGE OF ADDRESS */

SELECT * FROM NPI_LEGALS WHERE SFNAME = 'CHANGE OF ADDRESS'

SELECT
'APPEND PAGE|'+OBJECTLOCATION+'|'
+ISNULL(NEWCLIENTNO, '')+'PE|'
+ISNULL(NEWCLIENTNAME, '')+'|75|'
+ISNULL(SFNAME, '')+'||'
+SUBSTRING(ISNULL(SF2, '01-01-1900'),9,2)+'/'+SUBSTRING(ISNULL(SF2, '01-01-1900'),6,2)+'/'+SUBSTRING(ISNULL(SF2, '01-01-1900'),1,4)+'|'
+'||||'
FROM NPI_LEGALS
WHERE ISNULL(NEWCLIENTNO, '') <> 'BLANK'
AND ISNULL(SFNAME, '') = 'CHANGE OF ADDRESS'

/* Acorde input file for all uploadable objects - 255 LEGALS - DIVIDEND MANDATES */

SELECT * FROM NPI_LEGALS WHERE SFNAME = 'DIVIDEND MANDATES'

SELECT
'APPEND PAGE|'+OBJECTLOCATION+'|'
+ISNULL(NEWCLIENTNO, '')+'PE|'
+ISNULL(NEWCLIENTNAME, '')+'|75|'
+ISNULL(SFNAME, '')+'||'
+SUBSTRING(ISNULL(SF3, '01-01-1900'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '01-01-1900'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '01-01-1900'),1,4)+'|'
+'||||'
FROM NPI_LEGALS
WHERE ISNULL(NEWCLIENTNO, '') <> 'BLANK'
AND ISNULL(SFNAME, '') = 'DIVIDEND MANDATES'


/* Acorde input file for all uploadable objects - 16030 LEGALS - GENERAL CORRESPONDENCE */

SELECT * FROM NPI_LEGALS WHERE SFNAME = 'GENERAL CORRESPONDENCE'

SELECT
'APPEND PAGE|'+OBJECTLOCATION+'|'
+ISNULL(NEWCLIENTNO, '')+'PE|'
+ISNULL(NEWCLIENTNAME, '')+'|75|'
+ISNULL(SFNAME, '')+'|'
+SUBSTRING(ISNULL(SF2, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF2, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF2, '1900-01-01'),1,4)+'|'
+SUBSTRING(ISNULL(SF3, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),1,4)
+'||||'
FROM NPI_LEGALS
WHERE ISNULL(NEWCLIENTNO, '') <> 'BLANK'
AND ISNULL(SFNAME, '') = 'GENERAL CORRESPONDENCE'


/* Acorde input file for all uploadable objects - 146 LEGALS - LEGAL DOCUMENTS */

SELECT * FROM NPI_LEGALS WHERE SFNAME = 'LEGAL DOCUMENTS'

SELECT
'APPEND PAGE|'+OBJECTLOCATION+'|'
+ISNULL(NEWCLIENTNO, '')+'PE|'
+ISNULL(NEWCLIENTNAME, '')+'|75|'
+ISNULL(SFNAME, '')+'||'
+SUBSTRING(ISNULL(SF3, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),1,4)
+'||||'
FROM NPI_LEGALS
WHERE ISNULL(NEWCLIENTNO, '') <> 'BLANK'
AND ISNULL(SFNAME, '') = 'LEGAL DOCUMENTS'

/* Acorde input file for all uploadable objects - 7698 LEGALS - STOCK TRANSFER FORMS */

SELECT * FROM NPI_LEGALS WHERE SFNAME = 'STOCKTRANSFER FORMS'

SELECT
'APPEND PAGE|'+OBJECTLOCATION+'|'
+ISNULL(NEWCLIENTNO, '')+'PE|'
+ISNULL(NEWCLIENTNAME, '')+'|75|'
+ISNULL(SFNAME, '')+'||'
+SUBSTRING(ISNULL(SF3, '1900-01-01'),9,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),6,2)+'/'+SUBSTRING(ISNULL(SF3, '1900-01-01'),1,4)
+'||||'
FROM NPI_LEGALS
WHERE ISNULL(NEWCLIENTNO, '') <> 'BLANK'
AND ISNULL(SFNAME, '') = 'STOCKTRANSFER FORMS'








/* Count of unique FIFO indexes - 1263 */

SELECT * FROM NPI_FIFO

SELECT COUNT(DISTINCT(
'APPEND PAGE|'
+SUBSTRING(SF1,4,2)+'/'+SUBSTRING(SF1,1,2)+'/'+MF1+'|'
+'FIFO|||'))
FROM NPI_FIFO

/* Acorde input file for FIFO indexes - 87910 */

SELECT * FROM NPI_FIFO

SELECT
'APPEND PAGE|'
+OBJECTLOCATION+'|'
+SUBSTRING(SF1,4,2)+'/'+SUBSTRING(SF1,1,2)+'/'+MF1+'|'
+'FIFO|||'
FROM NPI_FIFO
ORDER BY SUBSTRING(SF1,4,2)+'/'+SUBSTRING(SF1,1,2)+'/'+MF1




/* Count of unique PRICES indexes - 1267 */

SELECT * FROM NPI_PRICES

SELECT COUNT(DISTINCT(
'APPEND PAGE|'
+SUBSTRING(SF1,4,2)+'/'+SUBSTRING(SF1,1,2)+'/'+MF1+'|'
+'PRICES|||'))
FROM NPI_PRICES

/* Acorde input file for PRICES indexes - 11770 */

SELECT * FROM NPI_PRICES

SELECT
'APPEND PAGE|'
+OBJECTLOCATION+'|'
+SUBSTRING(SF1,4,2)+'/'+SUBSTRING(SF1,1,2)+'/'+MF1+'|'
+'PRICES|||'
FROM NPI_PRICES
ORDER BY SUBSTRING(SF1,4,2)+'/'+SUBSTRING(SF1,1,2)+'/'+MF1





/* Count of unique RECS indexes - 422 */

SELECT * FROM NPI_RECS

SELECT COUNT(DISTINCT(
'APPEND PAGE|'
+SUBSTRING(SF1,4,2)+'/'+SUBSTRING(SF1,1,2)+'/'+CONVERT(VARCHAR(255), MF1)+'|'
+'RECS|||'))
FROM NPI_RECS

/* Acorde input file for RECS indexes - 18669 */

SELECT * FROM NPI_RECS

SELECT
'APPEND PAGE|'
+OBJECTLOCATION+'|'
+SUBSTRING(SF1,4,2)+'/'+SUBSTRING(SF1,1,2)+'/'+CONVERT(VARCHAR(255), MF1)+'|'
+'RECS|||'
FROM NPI_RECS
ORDER BY SUBSTRING(SF1,1,2)+'/'+CONVERT(VARCHAR(255), MF1)

backup log maximizer with truncate_only
SELECT *,CONVERT(Datetime, CONVERT(char(12), ArchDate) + ArchTime) FROM optika.CogentDocuments WHERE CliRef = '*' AND CliName = '*' AND CostCtr = '*' AND DocType = '*' AND DocDate = '01 Jan 1900' AND Barcode <> 'NO CODE'
select 'Count of Unique Index Lines referencing .doc files ', count(distinct(OBJECTID+IsNull(Worktype, ' ')+IsNull(CashAmount, ' ')+IsNull(ClientID, ' ')+IsNull(UnitHolderID, ' ')+IsNull(Idx3, ' ')+IsNull(Idx4, ' ')+IsNull(ObjectType, ' ')))  from HEND_IFDS where fullpath like '%doc'

select 'Total Number of Index Lines ', count(*) from HEND_IFDS

select 'Total Number of Index Lines with matching Objects ', count(*) from HEND_IFDS where fullpath is not null

select 'Total Number of Index Lines with no matching Object ', count(*) from HEND_IFDS where fullpath is null

select 'Count of Unique Index Lines with matching Objects ', count(distinct(OBJECTID+IsNull(Worktype, ' ')+IsNull(CashAmount, ' ')+IsNull(ClientID, ' ')+IsNull(UnitHolderID, ' ')+IsNull(Idx3, ' ')+IsNull(Idx4, ' ')+IsNull(ObjectType, ' '))) from HEND_IFDS where fullpath is not null

select 'Count of Unique Index Lines with no matching Object ', count(distinct(OBJECTID+IsNull(Worktype, ' ')+IsNull(CashAmount, ' ')+IsNull(ClientID, ' ')+IsNull(UnitHolderID, ' ')+IsNull(Idx3, ' ')+IsNull(Idx4, ' ')+IsNull(ObjectType, ' '))) from HEND_IFDS where fullpath is null

select 'Total Number of 0kb Files ', count(*) from [output]

select 'Total Number of Index Lines referencing 0kb files ', count(*) from [output],HEND_IFDS where col001 = fullpath

select 'Total Number of Unique 0kb files referenced in Index Lines ', count(distinct(OBJECTID+IsNull(Worktype, ' ')+IsNull(CashAmount, ' ')+IsNull(ClientID, ' ')+IsNull(UnitHolderID, ' ')+IsNull(Idx3, ' ')+IsNull(Idx4, ' ')+IsNull(ObjectType, ' '))) from [output],HEND_IFDS where col001 = fullpath

select 'Number of existing Unique Index Lines with ClientId but no Unit Holder ',count(distinct(OBJECTID+IsNull(Worktype, ' ')+IsNull(CashAmount, ' ')+IsNull(ClientID, ' ')+IsNull(UnitHolderID, ' ')+IsNull(Idx3, ' ')+IsNull(Idx4, ' ')+IsNull(ObjectType, ' '))) from HEND_IFDS where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0') and fullpath is not null

select distinct(OBJECTID+' '+IsNull(Worktype, ' ')+' '+IsNull(CashAmount, ' ')+' '+IsNull(ClientID, ' ')+' '+IsNull(UnitHolderID, ' ')+' '+IsNull(Idx3, ' ')+' '+IsNull(Idx4, ' ')+' '+IsNull(ObjectType, ' ')) from HEND_IFDS where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0') and fullpath is not null

select 'Number of Unique Index Lines with ClientId but no Unit Holder pointing at 0kb files ',count(distinct(OBJECTID+IsNull(Worktype, ' ')+IsNull(CashAmount, ' ')+IsNull(ClientID, ' ')+IsNull(UnitHolderID, ' ')+IsNull(Idx3, ' ')+IsNull(Idx4, ' ')+IsNull(ObjectType, ' '))) from HEND_IFDS,[OUTPUT] where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0') and COL001 = FULLPATH

select distinct(OBJECTID+'|'+IsNull(Worktype, ' ')+'|'+IsNull(CashAmount, ' ')+'|'+IsNull(ClientID, ' ')+'|'+IsNull(UnitHolderID, ' ')+'|'+IsNull(Idx3, ' ')+'|'+IsNull(Idx4, ' ')+'|'+IsNull(ObjectType, ' ')) from HEND_IFDS,[OUTPUT] where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0') and COL001 = FULLPATH

select 'Number of Unique Index Lines with ClientId but no Unit Holder ',count(distinct(OBJECTID+IsNull(Worktype, ' ')+IsNull(CashAmount, ' ')+IsNull(ClientID, ' ')+IsNull(UnitHolderID, ' ')+IsNull(Idx3, ' ')+IsNull(Idx4, ' ')+IsNull(ObjectType, ' '))) from HEND_IFDS where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0')

/* List of Unitholders that can be uploaded i.e. Image exists */
select distinct(UnitHolderID) from HEND_IFDS where fullpath is not null

select distinct(OBJECTID+'|'+IsNull(Worktype, ' ')+'|'+IsNull(CashAmount, ' ')+'|'+IsNull(ClientID, ' ')+'|'+IsNull(UnitHolderID, ' ')+'|'+IsNull(Idx3, ' ')+'|'+IsNull(Idx4, ' ')+'|'+IsNull(ObjectType, ' ')) from HEND_IFDS,[OUTPUT] where UNITHOLDERID ='0' and (clientid is not null and clientid <> '0') and fullpath is null
select count(*) from oracleapmain1
select * from oracleapmain1


select top 1000 * from oracleapmain1 order by invdate
select top 1000 * from acpmain1 order by invdate


SELECT
'EXPORT|*****|DocumentExport|RECID|' 
+ CONVERT(varchar(15), RECID)
+ '|EOFLD|-1|AllPages|NA|NA|NoMatchOK|AnnotsYes|9|TIFF|O:\Export\MOSS\'
+ CONVERT (VARCHAR(50), DATEPART(yy, INVDATE))
+ '\' 
+ CONVERT (VARCHAR(10), DATEPART(m, INVDATE))
+ '\'
+ CONVERT (VARCHAR(10), DATEPART(d, INVDATE))
+ '|INV|NA|NA|NA|NA|EOFLD|*****' 
FROM ORACLEAPMAIN1
WHERE INVDATE > '31 Dec 2000'
AND INVDATE < '01 Jan 2008'
ORDER BY INVDATE



SELECT TOP 1000 'EXPORT|*****|DocumentExport|RECID|' 
+ CONVERT(varchar(15), RECID)
+ '|EOFLD|-1|AllPages|NA|NA|NoMatchOK|AnnotsYes|9|TIFF|E:\Optika\Transact\ImageExport\ACP|INV|NA|NA|NA|NA|EOFLD|*****' 
FROM ACPMAIN1
ORDER BY INVDATE
backup log maximizer with truncate_only

以上是关于sql 旧版混合SQL语句的主要内容,如果未能解决你的问题,请参考以下文章

sql 旧版McAfee Helpdesk SQL语句

Mybatis 混合预处理语句和 sql 注入

如何用SQL语句,在数字加中文的混合数据中提取出中文

将旧版 SQL 查询转换为标准 SQL

旧版 sql 和标准 sql 之间的 BigQuery 表分区差异

如何将旧版 SQL BigQuery 转换为标准 SQL?