1
Create Proc Proc_Name
as begin
  SELECT 1111 AS sno,'--ALL--' AS RS.branch
  UNION 
  SELECT Rs.Sno,(RS.branch+'-'+RT.[Type] ) AS branch 
  FROM K_RT_MasterRetailStores Rs 
  INNER JOIN K_RT_RetailType RT ON RT.sno=RS.[Type] 
  ORDER BY Rs.Branch 
end

I am getting Incorrect syntax error near '.'. in SQL server. I am not able to find out my mistake. Please guide me.

1
  • Msg 102, Level 15, State 1, Procedure K_RT_GetRetailBranch, Line 16 Incorrect syntax near '.'. Its not working getting same exeception Commented Dec 21, 2013 at 9:27

2 Answers 2

2
Create Proc Proc_Name
as
begin 
    select *
    from
    (select 1111 as sno,'--ALL--' as branch
    union 
    select Rs.Sno, RS.branch + '-' + RT.[Type]
    from K_RT_MasterRetailStores Rs 
    inner join K_RT_RetailType RT on RT.sno = RS.[Type])
    order by Branch 
end
Sign up to request clarification or add additional context in comments.

1 Comment

I don't think order by Rs.Branch will work. The order by sorts the complete union result, not just one part of the union. And the result of the union does not have a column named RS.Branch only one that is called Branch
2

Remove the table name from the alias

select 1111 as sno, '--ALL--' as  branch
                                 ^--------------here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.