SQL 노트 [장기 업데이트] (- 2013.7)
14418 단어 sql
--IF EXISTS(SELECT * FROM dbo.SysObjects WHERE ID = object_id(N'[TABLEA]') ) DROP TABLE tableA
--CREATE TABLE TABLEA(
--Column1 VARCHAR(20),
--Column2 VARCHAR(20),
--Column3 VARCHAR(20),
--Column4 int,
--Column5 VARCHAR(20),
--Column6 DATETIME
--)
/*
--ROW_NUMBER() OVER(), case when :
select ROW_NUMBER() OVER(Order by a.Column1,a.Column2) AS rowid
,CASE WHEN a.Column3 IS NOT NULL THEN(
CASE WHEN a.Column3='1' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'I'
WHEN a.Column3='2' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'II'
WHEN a.Column3='3' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'III'
WHEN a.Column3='4' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'IV'
WHEN a.Column3='5' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'V'
WHEN a.Column3='6' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'VI'
WHEN a.Column3='7' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'VII'
WHEN a.Column3='8' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'VIII'
WHEN a.Column3='9' AND a.Column4 IS NOT NULL AND a.Column4 > 0 THEN 'IX'
ELSE '' END -- +'('+CONVERT(VARCHAR(20),a.Column4)+')'
)ELSE '' END AS
,
from TABLEA a
*/
/*
--
SELECT CAST(CONVERT(VARCHAR(20), DATEADD(MONTH,-1, DATEADD(DAY,1-DATEPART(DAY,GETDATE()),DATEADD(MONTH, 1,GETDATE()))) ,112) AS DATETIME)
--
SELECT CAST(CONVERT(VARCHAR(20),DATEADD(DAY,-DATEPART(DAY,GETDATE()),DATEADD(MONTH, 1,GETDATE())) ,112) AS DATETIME)
--
SELECT CAST(CONVERT(VARCHAR(20), DATEADD(DAY,1-DATEPART(DAY,GETDATE()),DATEADD(MONTH, 1,GETDATE())) ,112) AS DATETIME)
*/
/* -- :
create proc [SP_ B] (
@ID1 VARCHAR(400)=''
,@ID2 VARCHAR (400)='sdf7fgef-f4b0-4sfe-8ecb-cbgefb0fcfgh' --''
,@RESULT VARCHAR(100) output
)
as
BEGIN
DECLARE @ INT =1
DECLARE @RESULT_temp VARCHAR(100)=''
SET @RESULT=''
WHILE (@ <=9) --(CONVERT(int,@i))
BEGIN
SET @RESULT_temp=''
EXEC SP_ A @ 1=@ID1,@ 2=@ID2,@ =@ ,@RESULT=@RESULT_temp OUTPUT
IF @RESULT_temp IS NOT NULL AND @RESULT_temp <> ''
BEGIN
IF @RESULT='' --@ =1
BEGIN
SET @RESULT=@RESULT_temp
END
ELSE
BEGIN
SET @RESULT+=','+@RESULT_temp
END
END
SET @ +=1
END
END
*/
/* -- SQL , ( sql , )
DECLARE @ID VARCHAR(50)='JXsfge' -- , , @ID
DECLARE @i VARCHAR(400) =1
DECLARE @ 1 VARCHAR(20)=' 1'
DECLARE @ 2 VARCHAR(20)=' 2'
DECLARE @ 3 VARCHAR(20)=' 3'
DECLARE @ 11 VARCHAR(20)=' 11'
DECLARE @ 22 VARCHAR(20)=' 22'
DECLARE @ 33 VARCHAR(20)=' 33'
DECLARE @ C VARCHAR(20)=''
DECLARE @CNAME VARCHAR(20)=@ID
DECLARE @ temp VARCHAR(400) =''
DECLARE @ INT =''
DECLARE @ROWS VARCHAR(400) =''
EXEC SP_ C @ =@ID ,@ROWS1=@ROWS OUTPUT -- " "
-- @t_TableA、@t_TableX
declare @t_TableA table(j VARCHAR(10), VARCHAR(50), VARCHAR(50), VARCHAR(10), A VARCHAR(50),CISLATEST VARCHAR(50))
declare @t_TableX table(j VARCHAR(10), VARCHAR(50), VARCHAR(50), VARCHAR(10), A VARCHAR(50), VARCHAR(50),
VARCHAR(50), VARCHAR(500))
--
WHILE (CONVERT(int,@i))=(CONVERT(int,@ROWS))--@i=@ROWS
BEGIN
PRINT @i
INSERT INTO @t_TableA (j, , , , A,CISLATEST)(
SELECT TOP 1 * FROM (
SELECT ROW_NUMBER() OVER(ORDER BY TABLEB. DESC,TABLEB. A ASC) AS j ,
CASE WHEN TABLEB. =' ' THEN 'COM'
WHEN TABLEB. =' ' THEN 'EN'
WHEN TABLEB. =' ' THEN 'EM'
WHEN TABLEB. =' ' THEN 'ITRADE'
WHEN TABLEB. =' ' THEN 'M'
WHEN TABLEB. =' ' THEN 'C'
WHEN TABLEB. =' ' THEN 'SYS'
ELSE '' END AS ,
'1' AS ,TABLEB.IDA AS A,TABLEB.CISLATEST
FROM TABLEB
WHERE TABLEB. A = @ID AND TABLEB.CISLATEST='1'
) AS m1 WHERE m1.j=(CONVERT(int,@i))
)
-- ,@
SET @ A=(SELECT TOP 1 A FROM @t_TableA WHERE j=(CONVERT(int,@i)))
PRINT @ A
IF(@ temp =(SELECT TOP 1 FROM @t_TableA WHERE j=(CONVERT(int,@i))))
BEGIN
SET @ +=1
END
ELSE
BEGIN
SET @ =1
SET @ temp=(SELECT TOP 1 FROM @t_TableA WHERE j=(CONVERT(int,@i)))
END
SET @ 1=''
SET @ 2=''
SET @ 3=''
SET @ 11=''
SET @ 22=''
SET @ 33=''
EXEC SP_ B @ =@ 1,@CNAME=@CNAME,@ =@ 11 OUTPUT,@ =''
EXEC SP_ B @ =@ 2,@CNAME=@CNAME,@ =@ 22 OUTPUT,@ =''
EXEC SP_ B @ =@ 3,@CNAME=@CNAME,@ =@ 33 OUTPUT,@ =@ C OUTPUT --
DELETE FROM @t_TableA --
PRINT ' 11 :'+@ 11+' 22:'+@ 22+' 33:'+@ 33
--
BEGIN
INSERT INTO @t_TableX (j, , , , A , , )(
SELECT TOP 1 * FROM (
SELECT ROW_NUMBER() OVER(ORDER BY TABLEB. DESC,TABLEB. A ASC) AS j ,
CASE WHEN TABLEB. =' ' THEN 'COM'
WHEN TABLEB. =' ' THEN 'EN'
WHEN TABLEB. =' ' THEN 'EM'
WHEN TABLEB. =' ' THEN 'ITRADE'
WHEN TABLEB. =' ' THEN 'M'
WHEN TABLEB. =' ' THEN 'C'
WHEN TABLEB. =' ' THEN 'SYS'
ELSE '' END AS ,
'1' AS ,TABLEB.IDA AS A,TABLEB.CISLATEST,
@ 11+@ 22+@ 33
FROM TABLEB
WHERE = @ID AND TABLEB.CISLATEST='1'
) AS m1 WHERE m1.j=(CONVERT(int,@i))
)
END
SET @i+=1
END
SELECT j, , , , A , , FROM @t_TableX
*/
다운로드 주소: http://files.cnblogs.com/jx270/SQL.rar
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
깊이 중첩된 객체를 정확히 일치 검색 - PostgreSQL목차 * 🚀 * 🎯 * 🏁 * 🙏 JSON 객체 예시 따라서 우리의 현재 목표는 "고용주"사용자가 입력한 검색어(이 경우에는 '요리')를 얻고 이 용어와 정확히 일치하는 모든 사용자 프로필을 찾는 것입니다. 즐거운 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.