Solved

tsql check field if is a number from 1 to 40 ??

Posted on 2012-12-24
3
346 Views
Last Modified: 2012-12-25
i have field @message selected from
select @message = message from inserted
select @reqport = reqport from inserted
i want to check if this @message is between 1 to 40
maybe the message contain other word i want to check if it's numeric and if @message is a number from 1 to 40

and i want to add for the first one to check if @reqport is 1234 or 4567 or 7890 and the message between 1 to 40

how i can write this using if (
0
Comment
Question by:afifosh
3 Comments
 
LVL 1

Expert Comment

by:igordevelop
ID: 38719959
Hi,

IF @message > 1 and @message < 40
BEGIN
  //SOME SQL
END
ELSE
 //SOME SQL

same goes for @reqport

IF @reqport = 1234 OR @reqport = 4567 OR @reqport = 7890
BEGIN
 //SOME SQL
END
ELSE
 //SOME SQL
0
 
LVL 1

Author Comment

by:afifosh
ID: 38719964
i want to match the two restriction in the same time
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 38719974
Maybe
IF @message between 1 and 40 and @reqport in (1234, 4567, 7890)
BEGIN
  -- sql if true
END
ELSE
BEGIN
  -- sql if false
END

Open in new window

0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question