I am very new in sql programming .i have 2 questions based on the below mentioned query
WITH CTE_Stars AS
(
SELECT CONVERT(VARCHAR(10), '*') Stars
UNION ALL
SELECT CONVERT(VARCHAR(10), CTE_Stars.Stars+'*') Stars
FROM CTE_Stars
WHERE LEN(Stars) < 6
)
SELECT *
FROM CTE_Stars
Can someone explain how the above query is working and second this query does not work without convert function why..? Why do we need to convert '*' to character? By default *
datatype is character only.
This query is giving output in 5 rows and that to without a loop.. how is this possible
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
WITH CTE_Stars AS (SELECT
CONVERT(VARCHAR(10),
'*') Stars
UNION
ALL SELECT
CONVERT(VARCHAR(10),
CTE_Stars.Stars + '*') Stars
FROM
CTE_Stars
WHERE
LEN(Stars) < 6) SELECT
*
FROM
CTE_Stars