์ฟผ๋ฆฌ๋ฌธ์ ์์ฑํ๋ค๋ณด๋ฉด ๋น๊ต๋ฌธ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ๊ฐ ์๊ธฐ๋๋ฐ..
๋ง์ด๋ฐํฐ์ค์์๋ <,>,<= ๋ฑ๊ณผ ๊ฐ์ ๋ถ๋ฑํธ๋ฅผ ์ฌ์ฉํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค...
๋ง์ด๋ฐํฐ์ค์์๋ ๋น๊ต์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ
๋น๊ต ์ฐ์ฐ์์ธ์ง ๊ดํธ์ธ์ง ๊ตฌ๋ถ์ ๋ชปํด์ Error ๊ฐ ๋จ์ด์ง๋ค๊ณ ํจ.
๋ญ๊ฐ ๋ค๋ฅธ ์ฐ๋ ๋ฐฉ๋ฒ์ด ์๋ ๋ฏ ํ๋ค.
๊ทธ "๋ค๋ฅธ ์ฐ๋ ๋ฐฉ๋ฒ"์ ๋ํด ์์๋ณด์.
์ฐ์ ๋ด๊ฐ ์์ฑํ
์๋ชป๋ ์ฝ๋
<update id="siteCalendarCreate" parameterType="HashMap">
WITH CTE(WorkDate) AS (
SELECT CONVERT ( DATE, #{Year}+'-01-01')
UNION ALL
SELECT DATEADD(d, 1, WorkDate)
FROM CTE
WHERE WorkDate < (CONVERT(DATE, #{Year}+'-12-31'))
)
SELECT * FROM CTE OPTION ( MAXRECURSION 0 );
</update>
ํด๊ฒฐ๋ฐฉ๋ฒ 1. CDATA
CDATA ๋ก ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ๋๊ฐ์ง์ด๋ค.
ํ๋. <![CDATA["๋ถ๋ฑํธ"]]>
<update id="siteCalendarCreate" parameterType="HashMap">
WITH CTE(WorkDate) AS (
SELECT CONVERT ( DATE, #{Year}+'-01-01')
UNION ALL
SELECT DATEADD(d, 1, WorkDate)
FROM CTE
WHERE WorkDate <![CDATA["<"]]> (CONVERT(DATE, #{Year}+'-12-31'))
)
SELECT * FROM CTE OPTION ( MAXRECURSION 0 );
</update>
๋. <![CDATA[์๋ชป๋ ์ฟผ๋ฆฌ๋ฌธ]]>
<update id="siteCalendarCreate" parameterType="HashMap">
WITH CTE(WorkDate) AS (
SELECT CONVERT ( DATE, #{Year}+'-01-01')
UNION ALL
SELECT DATEADD(d, 1, WorkDate)
FROM CTE
WHERE <![CDATA[WorkDate < (CONVERT(DATE, #{Year}+'-12-31'))]]>
)
SELECT * FROM CTE OPTION ( MAXRECURSION 0 );
</update>
ํด๊ฒฐ๋ฐฉ๋ฒ 2. gt, lt
๋์ฒด์์ ์ด์ฉํ์ฌ ๋ฌธ๋ฒ์ ๋ง์ถฐ์ฃผ๋ ๋ฐฉ๋ฒ์ด๋ค.
<update id="siteCalendarCreate" parameterType="HashMap">
WITH CTE(WorkDate) AS (
SELECT CONVERT ( DATE, #{Year}+'-01-01')
UNION ALL
SELECT DATEADD(d, 1, WorkDate)
FROM CTE
WHERE WorkDate < (CONVERT(DATE, #{Year}+'-12-31'))
)
SELECT * FROM CTE OPTION ( MAXRECURSION 0 );
</update>
๊ธฐํธ | ๋์ฒด์ | ์์ |
< | lt | workDate < '2024-01-01' |
> | gt | workDate > '2024-01-01' |
when ์ด๋ if์ ์ test์์ ๋ถ๋ฑํธ๋ฅผ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด
๋์ฒด์์ ์ฌ์ฉํ์ฌ ํ๊ธฐํด์ฃผ๋ฉด ๋๋ค.
<if test = ' workDt > 2024-01-01 ' > ์ ๊ฒฝ์ฐ๋ <if test = 'workDt lt 2024-01-01' > ์ ํ์์ผ๋ก ์ฌ์ฉํ๋ฉด ๋จ.