Hi
I have below code . I want if Closing Balance is -ve then its value should be Red. Can it be done thru HTML in stored procedure
(SELECT 'A/C Bal.' 'Type',cast(getdate() as date) [Posting Date],'' [Document No],'' [Voucher No.],'' Line_ID,'ABC Bank Ltd' + ' ' +'('+' '+'Closing Bal.'+' '+'='+' '+cast(cast(ISNULL(SUM(S.Debit)-SUM(s.Credit),0.00) +(select sum(debit)-sum(Credit) from jdt1 where jdt1.refdate
Thanks
Saravanan GanesanPosted Aug 16, 2023, 5:38 PM
In HTML and within a stored procedure, you can't directly apply conditional formatting like changing the color based on a value. HTML alone doesn't provide this capability. However, you can achieve this using CSS or JavaScript in conjunction with your HTML output.
In your scenario, it's not recommended to handle such styling within a stored procedure; it's better suited for the presentation layer. You could generate the HTML output from your stored procedure and then, in your web application's frontend, use JavaScript or CSS to identify negative values and apply a red color.
In your HTML generated by the stored procedure:
-100.00This script will find all elements with the class
closing-balance, check their values, and if negative, apply the red color.Remember, separating business logic (like calculation of values) from presentation logic (like styling) is a best practice for maintainable and clean code.
Lokesh VarmanPosted Aug 16, 2023, 1:48 AM
It seems like you're trying to generate some HTML content within a stored procedure based on certain conditions. While stored procedures are primarily used for database operations and querying data, generating HTML directly within a stored procedure might not be the best approach. Instead, you could retrieve the necessary data from the database using the stored procedure and then use HTML in your application code (e.g., in a web page or a reporting tool) to apply styling based on the conditions you mentioned.
Here's a simplified example of how you might structure your code:
In this example, the SQL code calculates the closing balance and generates HTML markup with conditional styling based on the closing balance. However, it's important to note that embedding HTML directly within a stored procedure is not a common practice. Typically, the data would be retrieved through a stored procedure and then formatted and displayed using application code (e.g., PHP, ASP.NET, JavaScript, etc.) to handle the presentation layer and styling.