472,989 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

If statments in MSSQL

17
Iím am trying to create a StoredProc that will, if a value is below a limit it will insert one value or if the value is above a limit then it will insert another value. Sort of like this in C programming:

Expand|Select|Wrap|Line Numbers
  1.             if (ValueOriginal >= 3)
  2.             {
  3.                 if (ValueOriginal <= 10)
  4.                     ValueToInsert = ValueOriginal;
  5.                 else
  6.                     ValueToInsert = 0;
  7.             }
  8.             else
  9.                 ValueToInsert = 0;
Hope Someone can help me

NormanTheDane
Mar 2 '07 #1
4 33985
prileep
20
Iím am trying to create a StoredProc that will, if a value is below a limit it will insert one value or if the value is above a limit then it will insert another value. Sort of like this in C programming:

Expand|Select|Wrap|Line Numbers
  1.             if (ValueOriginal >= 3)
  2.             {
  3.                 if (ValueOriginal <= 10)
  4.                     ValueToInsert = ValueOriginal;
  5.                 else
  6.                     ValueToInsert = 0;
  7.             }
  8.             else
  9.                 ValueToInsert = 0;
Hope Someone can help me

NormanTheDane
If u just want to know how to use IF state ment in SQL Server,

Format one:
IF <condition> <then code to be executed when condition true>
Format two:
IF <condition>
BEGIN
<then code to be executed when condition true>
END
ELSE
BEGIN
< else code to be executed when condition is false>
END
Mar 2 '07 #2
almaz
168 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. insert <<YourTableName>> (<<ListOfFields>>) values 
  2. (case 
  3.     when @ValueOriginal >= 3 and @ValueOriginal <= 10 then @ValueOriginal 
  4.     else 0 
  5. end, <<OtherFields>>)
Mar 2 '07 #3
hariharanmca
1,977 1GB
Iím am trying to create a StoredProc that will, if a value is below a limit it will insert one value or if the value is above a limit then it will insert another value. Sort of like this in C programming:

Expand|Select|Wrap|Line Numbers
  1.             if (ValueOriginal >= 3)
  2.             {
  3.                 if (ValueOriginal <= 10)
  4.                     ValueToInsert = ValueOriginal;
  5.                 else
  6.                     ValueToInsert = 0;
  7.             }
  8.             else
  9.                 ValueToInsert = 0;
Hope Someone can help me

NormanTheDane


Expand|Select|Wrap|Line Numbers
  1.   if  ValueOriginal >= 3
  2.             Begin
  3.                 if  ValueOriginal <= 10 
  4.                     ValueToInsert = ValueOriginal
  5.                 else
  6.                     ValueToInsert = 0
  7.             end
  8.             else
  9.                 ValueToInsert = 0

Try This
Mar 2 '07 #4
Normann
17
Thanks for all your help, I have it working now.
Mar 2 '07 #5

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

Similar topics

11
by: badz | last post by:
Hi frenz Lately I try to use MSSQL and PHP , the problem arise when PHP try to read MSSQL field with 'image' data type, header("Content-type: image/jpeg"); // act as a jpg file to browser I...
7
by: mj | last post by:
Hello, thanks for the help. I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm firewall) Apache 2.0.52 MySQL 4.1.7 PHP 5.1.0-dev I have developed a PHP/MySQL web app that...
1
by: JackTorrance | last post by:
Hi i have a problem with IIS6 and MSSQL and i hope that someone can help me. this is the configuration: Windows 2003 IIS6 MSSQL 7.0 Standard Edition ADO 2.5
14
by: Kukurydz | last post by:
I've got such problem: My database is stored on MSSQL Server. I have to write reports for it in MSAccess. I've got a problem with creating a query which will select records from MSSQL table with...
3
by: gharmel | last post by:
I'm trying to get some clues on why I get (much) slower responses from my PHP applications when dealing with a remote sql server as opposed to a local sql server. Here's my situation: Server...
11
by: ralphie | last post by:
hi all since nearly 2 days i fight with mssql and utf-8 as i need to store and retrieve arabic characters. i tried the com approach ...
0
by: DariuszK | last post by:
I am greeting I would like to consult the better solution(with security consideration) to the access is for MSSQL(2005) from ASP(Classic) in the system of the intranet. a) SQL mixed mode and...
8
by: php-taz | last post by:
I built a PHP website on Windows 2000 (using IIS) that connects to a SQL Server 2000 database using the mssql functions. I migrated the website and the database onto a Windows 2003 machine, and...
0
by: Derftics | last post by:
Hi Guys, Is there anyone who have tried installing MSSQL 2000 and MSSQL 2005 servers in one desktop computer? I have tried using MSDE and successfully install the MSSQL 2000 server but when I...
14
by: guswebb | last post by:
Hi. I'm a newbie to PHP and am having a few problems as follows... I have installed PHP successfully on server 1 which is running IIS 6 (W2k3) and hosting multiple sites, some of which connect to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.