I want users to have the option to ORDER BY data before creating the report.
ORDER BY is defined with 3 values (database column names); this call goes with the stored procedure.
For some reason, I get errors and don't understand why they show. The same error appears if the stored procedure is triggered via the app, or if I execute the stored procedure using MSSMS. Pictures should provide more about this problem.
So basically, I want the SELECT statement to be ORDERED by how the user has chosen before the report is created.
![Name: errorapp.png
Views: 42
Size: 18.0 KB]()
![Name: errormssms.jpg
Views: 42
Size: 18.8 KB]()
MG varchar(8), marka varchar(200), dat_unosa date. It bothers me that the query wants to convert the string to date/time, which is unnecessary. It only needs to use that column and order by its values.
ORDER BY is defined with 3 values (database column names); this call goes with the stored procedure.
Code:
ALTER PROCEDURE [dbo].[vozila_report_all_servisi]
@MySelect varchar(8),
@MyOrderBy varchar(20)
AS
SELECT reg,dat_unosa,zaduzio,marka,model,godiste,gorivo,zapremina,kilometri,trenutni_kilometri,ukupno_kilometri,vrsta_vozila,vrsta_servisa,servis,detaljno,ukupno_placeno
FROM vozila_servisi
WHERE @MySelect=RIGHT(MG, 4)
ORDER BY
CASE
WHEN @MyOrderBy ='Reg Oznaka' THEN reg
WHEN @MyOrderBy='Marka' THEN marka
ELSE dat_unosa
END
So basically, I want the SELECT statement to be ORDERED by how the user has chosen before the report is created.
MG varchar(8), marka varchar(200), dat_unosa date. It bothers me that the query wants to convert the string to date/time, which is unnecessary. It only needs to use that column and order by its values.