473,503 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert the SQL-C# logic to syntactically-correct SQL code (SQL Server 2005)?

4 New Member
How to convert the following SQL-C# logic to syntactically-correct SQL code (SQL Server 2005)?

"Description", "LeaveType", "MonthlyMaxLeave", "YearlyMaxLeave" are the column names in the table EmpTab.

I have written a basic logic to calculate the PayLeave and NonPayLeave, and to display its final values. Assume that the fields "Description" and "LeaveType" always contains the values "Sick" and "Yearly" respectively. Please do not worry about the data in the table. The field values in the table may be customized as per the requirements.

Just correct the syntax in the code so as to meet the SQL standards, as well as to display the PayLeave and NonPayLeave values based on the calculation logic shown below.



Expand|Select|Wrap|Line Numbers
  1. USE [Emp1]
  2. GO
  3.  
  4.  
  5. CREATE FUNCTION [dbo].[Leave] 
  6. (  
  7.    @EmployeeID INT    
  8. )
  9. RETURNS INT  
  10. AS  
  11.  
  12. BEGIN 
  13.  
  14. DECLARE    @PayLeave INT,
  15.     @NonPayLeave INT;
  16.  
  17. SET @PayLeave = 0;
  18. SET @NonPayLeave = 0;
  19.  
  20. RETURN
  21. (
  22.     SELECT
  23.     IF((ImDescription == "Sick") AND (ImLeaveType == "Yearly"))
  24.     {
  25.         IF((ImMonthlyMaxLeave > 1) OR (ImYearlyMaxLeave > 10 ))
  26.         {
  27.             @NonPayLeave = @NonPayLeave + 1;
  28.             PRINT @NonPayLeave;
  29.         }        
  30.         ELSE
  31.         {    
  32.             @PayLeave = @PayLeave + 1;
  33.             PRINT @PayLeave;
  34.         }
  35.     }
  36. )
  37.  
  38. END
  39.  
  40.  
  41.  
  42. --PRINT dbo.Leave('123')
  43.  
  44.  
  45.  
Mar 15 '13 #1
1 1790
Rabbit
12,516 Recognized Expert Moderator MVP
This is not a code writing service but if you post your attempt at the conversion, we can help guide you to a solution.
Mar 15 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

19
7246
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
1
1787
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance...
2
8896
by: Joel Moore | last post by:
Maybe I'm just easily baffled after an all-nighter but I can't seem to figure out how to represent a BitArray as a hexadecimal string. For example: Dim outputBank As New BitArray(8) ...
3
7722
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
1
2500
by: Sam Smith | last post by:
Hi, I wan't a function to take a const char*, a start bit position and number of bits and convert that bit-stream into a primitive of desired type. I.e. something like: char convert(const...
19
4107
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
4
3600
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
2
2302
by: amitkhemlani | last post by:
Hello All, I have data in the form of characters Ex: "Amit". I convert the data from its character representation to its ascii values so "Amit" gets converted to "97 109 105 116". I then convert...
6
4239
by: Ken Fine | last post by:
This is a basic question. What is the difference between casting and using the Convert.ToXXX methods, from the standpoint of the compiler, in terms of performance, and in other ways? e.g. ...
9
17492
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.