SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Greater Than And Less Than
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Hinduson
Yak Posting Veteran

Ghana
57 Posts

Posted - 09/20/2013 :  19:17:37  Show Profile  Reply with Quote
What is the Syntax for running the Greater THAN or Less THAN Querries in SQL SERVER 2005?

Best Regards.

SwePeso
Patron Saint of Lost Yaks

Sweden
30265 Posts

Posted - 09/20/2013 :  20:20:59  Show Profile  Visit SwePeso's Homepage  Reply with Quote
You mean "Not Equal To"? SELECT * FROM dbo.Table1 WHERE Age <> 15;



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/22/2013 :  04:16:40  Show Profile  Reply with Quote
or is it

WHERE Age > somevalue 
and Age < Somevalue


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Hinduson
Yak Posting Veteran

Ghana
57 Posts

Posted - 09/26/2013 :  18:46:29  Show Profile  Reply with Quote
No i mean am now creating that rule , or how do i say it. I need the syntax or formula for implementing the greater than or Less than rule is a table please.

Best Regards.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30265 Posts

Posted - 09/27/2013 :  02:36:46  Show Profile  Visit SwePeso's Homepage  Reply with Quote
You want a CHECK CONSTRAINT?



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

Hinduson
Yak Posting Veteran

Ghana
57 Posts

Posted - 09/27/2013 :  12:04:23  Show Profile  Reply with Quote
Meaby SwePeso.. You tell me and can you please show me how to write or go about the syntax so that i won't get any errors while executing ..

Thanks SwePeso

Best Regards.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3707 Posts

Posted - 09/27/2013 :  12:46:32  Show Profile  Reply with Quote
Use the first if you are creating the table; if the table already exists and you want to add the constraint, use the second
CREATE TABLE BTestTable
(
	id INT 
	CONSTRAINT check_ID CHECK (id >= 0 AND id <= 10)
);

CREATE TABLE CTestTable
(
	id INT
);
ALTER TABLE CTestTable ADD CONSTRAINT CCheck_ID CHECK (id >= 0 AND id <= 10) 
Go to Top of Page

Hinduson
Yak Posting Veteran

Ghana
57 Posts

Posted - 09/27/2013 :  12:48:07  Show Profile  Reply with Quote
Thanks James K

Best Regards.
Go to Top of Page

Hinduson
Yak Posting Veteran

Ghana
57 Posts

Posted - 09/28/2013 :  11:03:13  Show Profile  Reply with Quote
James K .. Please am getting errors when i create the table. Below is how i wrote my query. Please check for errors .. And the question is [QUANTITYINHAND should be greater than 0. The record should not be inerted or modified manually if QUANTITYINHAND is 0.

QUANTITYINHAND INT,
CONSTRAINT CHECK_QUANTITYINHAND CHECK (QUANTITYINHAND > 0 )

Best Regards.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/29/2013 :  03:05:25  Show Profile  Reply with Quote
the posted query part doesnt have any obvious issues. Show us full create script please. Also post the error message you got.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Hinduson
Yak Posting Veteran

Ghana
57 Posts

Posted - 10/01/2013 :  03:01:36  Show Profile  Reply with Quote

CREATE TABLE ITEMS_ITEMDETAILS
(
ItemID int Identity(2,2) PRIMARY KEY ,
ItemName Varchar (50) not null,
ItemDescription Varchar (50) not null,
QuantityInHand int,
CONSTRAINT check_ID CHECK (QuantityInHand >= 0 )
UnitPrice Money,
CONSTRAINT check_ID CHECK (UnitPrice >= 0 )
ReorderQuantity int,
CONSTRAINT check_ID CHECK (ReorderQuantity >= 0 )
)

Msg 102, Level 15, State 1, Line 8
Incorrect syntax near 'UnitPrice'.



Best Regards.
Go to Top of Page

VeeranjaneyuluAnnapureddy
Posting Yak Master

India
169 Posts

Posted - 10/01/2013 :  03:19:32  Show Profile  Reply with Quote
CREATE TABLE ITEMS_ITEMDETAILS
(
ItemID int Identity(2,2) PRIMARY KEY ,
ItemName Varchar (50) not null,
ItemDescription Varchar (50) not null,
QuantityInHand int,
CONSTRAINT check_ID1 CHECK (QuantityInHand >= 0 ),
UnitPrice Money,
CONSTRAINT check_ID2 CHECK (UnitPrice >= 0 ),
ReorderQuantity int,
CONSTRAINT check_ID3 CHECK (ReorderQuantity >= 0 )
)

veeranjaneyulu
Go to Top of Page

Hinduson
Yak Posting Veteran

Ghana
57 Posts

Posted - 10/01/2013 :  16:39:02  Show Profile  Reply with Quote
Thanks Alot Brother VeeranjaneyuluAnnapureddy.. I have learnt from you and I really appreciate it. But i have one last question. please if you are asked a question like this how will you go about it.

Phone number must be in the following format : '[0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9]'

I tried to build a rule, and sp_bindrule to bind the rule to the table. But when inserting values it give me errors. So please I will like you to help me out or anyone else around ..

Thanks alot brothers.

Best Regards.
Go to Top of Page

marcusn25
Yak Posting Veteran

Germany
51 Posts

Posted - 10/14/2013 :  16:28:38  Show Profile  Reply with Quote
ALTER TABLE [TABLE NAME]
ADD CONSTRAINT CK_PhoneNumber
CHECK ( [PhoneNumber] LIKE '[0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9]' )

M. Ncube

Edited by - marcusn25 on 10/14/2013 16:30:05
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/15/2013 :  01:15:16  Show Profile  Reply with Quote
if PhoneNumber must have only numeric data why not make it integer?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000