Prasad Anumolu

Prasad Anumolu

  • NA
  • 15
  • 1.8k

Query to split string from comma

Feb 10 2016 3:15 AM
DECLARE @str varchar(50)='Hello, world'; /* SQL SERVER QUERY TO SPLIT STRING FROM COMMA AND GET LEFT AND RIGHT PART */
SELECT LEFT(@str, CHARINDEX(',', @str)-1) as LeftPart, RIGHT(@str, LEN(@str)-CHARINDEX(',', @str)) as RightPart;
Error is
Must declare the scalar variable "@str"
 
why it is coming ? if any one know tell me friends 

Answers (5)