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
 General SQL Server Forums
 New to SQL Server Programming
 need syntax for simple query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AdamWest
Constraint Violating Yak Guru

USA
351 Posts

Posted - 10/21/2013 :  17:20:09  Show Profile  Reply with Quote
HI I have to select rows from a table
if the first 2 characters of a 12 char column are
'GB'

Select BFKEYC from table where

I have a hokey way of doing it but it looks embarrassing:

BFKEYC GT 'GA9999999999'
AND BFKEYC LT 'GC'

bitsmed
Constraint Violating Yak Guru

322 Posts

Posted - 10/21/2013 :  17:38:38  Show Profile  Reply with Quote
where bfkeyc like 'GB%'

Edited by - bitsmed on 10/21/2013 17:39:28
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 10/22/2013 :  00:21:49  Show Profile  Reply with Quote
Two approaches for the above requirement are:
1) where bfkeyc like 'GB%'

2) WHERE LEFT( bfkeyc, 2) = 'GB'

--
Chandu
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 10/22/2013 :  06:10:39  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by bandi

Two approaches for the above requirement are:
1) where bfkeyc like 'GB%'

2) WHERE LEFT( bfkeyc, 2) = 'GB'

--
Chandu


Method 1 is good if there is an index on that column

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 10/22/2013 :  08:04:22  Show Profile  Reply with Quote
GT LT? Are you using T-SQL? having seen these functions so far.

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

AdamWest
Constraint Violating Yak Guru

USA
351 Posts

Posted - 10/23/2013 :  08:16:42  Show Profile  Reply with Quote
this is db2 as400 they still have these.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 10/23/2013 :  08:34:36  Show Profile  Reply with Quote
Hmm..then you are in wrong forum.
This is MS SQL Server forum

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

AdamWest
Constraint Violating Yak Guru

USA
351 Posts

Posted - 10/23/2013 :  09:02:50  Show Profile  Reply with Quote
Yes but I am using Crystal reports which is sql server
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 10/23/2013 :  09:08:51  Show Profile  Reply with Quote
quote:
Originally posted by AdamWest

Yes but I am using Crystal reports which is sql server


Crystal Reports is just a component of sql server. But if you're using AS400 as backend the query syntax would be different from T-SQL which is MS SQL Servers programming language. Thats why I suggested you to try in AS400 related forums as there are not much experts on AS400 here

------------------------------------------------------------------------------------------------------
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.05 seconds. Powered By: Snitz Forums 2000