yelp please...
This one fails when 1,2,3,4 is entered (ive done @orderby in int and varchar, same results) Stripped down to basics, still same result...
Syntax error converting character string to smalldatetime data type.
This one almost works...but the date, #7 doesnt order properly because its a varchar. If i cast again as sdt, it will order properly, but then 1 - 6 fail with error above.
If i only convert #7, then a couple more options fail.
Why is the order by setting the data type? when i use @orderby as an int, it states error converting to datatype int.
Thanks for any input for my output!
Adam
This one fails when 1,2,3,4 is entered (ive done @orderby in int and varchar, same results) Stripped down to basics, still same result...
Syntax error converting character string to smalldatetime data type.
Code:
DECLARE @level int, @orderby varchar(1)
SET @level = 3
SET @orderby = '6'
SELECT Configurations.PartNumber,Configurations.configType,
Configurations.RevisionNumber,Formulations.MoldOption, Configurations.ODInch,
Configurations.IDInch, tblAuditActions.auditDate,
(SELECT t2.AuditTypeDesc FROM tblAuditActionType t2 WHERE t2.auditTypeID = tblAuditActions.auditTypeID + 1)As AuditTypeDesc,
tblAuditActions.auditTypeID
FROM Configurations INNER JOIN
Formulations ON Configurations.ConfigurationID = Formulations.ConfigurationID INNER JOIN
tblAuditActions ON Formulations.FormulationID = tblAuditActions.linkID INNER JOIN
tblAuditActionType ON tblAuditActions.auditTypeID = tblAuditActionType.AuditTypeID
WHERE ((SELECT COUNT(t1.LinkID)
FROM tblAuditActions t1
WHERE t1.LinkID = Formulations.FormulationID AND t1.auditTypeID < 5) = @level)
AND tblAuditActions.auditTypeID = @level
ORDER BY
CASE
WHEN @orderby = '1' THEN Configurations.PartNumber
WHEN @orderby = '2' THEN Configurations.configType
WHEN @orderby = '3' THEN Configurations.RevisionNumber
WHEN @orderby = '4' THEN Formulations.MoldOption
WHEN @orderby = '5' THEN Configurations.ODInch
WHEN @orderby = '6' THEN Configurations.IDInch
WHEN @orderby = '7' THEN tblAuditActions.auditDate
END
DESC
This one almost works...but the date, #7 doesnt order properly because its a varchar. If i cast again as sdt, it will order properly, but then 1 - 6 fail with error above.
Code:
DECLARE @level int, @orderby varchar(1)
SET @level = 3
SET @orderby = '6'
SELECT Configurations.PartNumber,Configurations.configType,
Configurations.RevisionNumber,Formulations.MoldOption, Configurations.ODInch,
Configurations.IDInch, tblAuditActions.auditDate,
(SELECT t2.AuditTypeDesc FROM tblAuditActionType t2 WHERE t2.auditTypeID = tblAuditActions.auditTypeID + 1)As AuditTypeDesc,
tblAuditActions.auditTypeID
FROM Configurations INNER JOIN
Formulations ON Configurations.ConfigurationID = Formulations.ConfigurationID INNER JOIN
tblAuditActions ON Formulations.FormulationID = tblAuditActions.linkID INNER JOIN
tblAuditActionType ON tblAuditActions.auditTypeID = tblAuditActionType.AuditTypeID
WHERE ((SELECT COUNT(t1.LinkID)
FROM tblAuditActions t1
WHERE t1.LinkID = Formulations.FormulationID AND t1.auditTypeID < 5) = @level)
AND tblAuditActions.auditTypeID = @level
ORDER BY
CASE
WHEN @orderby = '1' THEN CONVERT(varchar(50),Configurations.PartNumber)
WHEN @orderby = '2' THEN CONVERT(varchar(50),Configurations.configType)
WHEN @orderby = '3' THEN CONVERT(varchar(50),Configurations.RevisionNumber)
WHEN @orderby = '4' THEN CONVERT(varchar(50),Formulations.MoldOption)
WHEN @orderby = '5' THEN CONVERT(varchar(50),Configurations.ODInch)
WHEN @orderby = '6' THEN CONVERT(varchar(50),Configurations.IDInch)
WHEN @orderby = '7' THEN CONVERT(varchar(50),tblAuditActions.auditDate)
END
DESC
If i only convert #7, then a couple more options fail.
Why is the order by setting the data type? when i use @orderby as an int, it states error converting to datatype int.
Thanks for any input for my output!
Adam