dbTalk Databases Forums  

Simple Query - I need to select the value from one column

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Simple Query - I need to select the value from one column in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
colin spalding
 
Posts: n/a

Default Simple Query - I need to select the value from one column - 11-03-2010 , 07:09 AM






I have been away from this for a long time and seem to have forgotten
much of which I learned. This syntax will always only ever return one
record and I need to use the value returned in the column
"IPT_Rates.IPT_Percentage". What am I missing? Is the use of
"Column() if so where?
Thanks in advance from one frustrated brain dead amateur.

Dim iptCurrent As String

iptCurrent = "SELECT IPT_Rates.IPT_Percentage,
IPT_Rates.IPT_RateChangeStartDate, IPT_Rates.IPT_RateChangeFinish " _
& "FROM IPT_Rates " _ & "GROUP BY IPT_Rates.IPT_Percentage,
IPT_Rates.IPT_RateChangeStartDate, IPT_Rates.IPT_RateChangeFinish " _
& "HAVING (((IPT_Rates.IPT_RateChangeStartDate)<=([Forms]![frmPolicy]!
[txtPeriodStartDate])) " _
& "AND ((IPT_Rates.IPT_RateChangeFinish)>=([Forms]![frmPolicy]!
[txtPeriodStartDate])));"

Reply With Quote
  #2  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Simple Query - I need to select the value from one column - 11-03-2010 , 08:41 AM






On Wed, 3 Nov 2010 06:09:47 -0700 (PDT), colin spalding
<colin.mardell (AT) btopenworld (DOT) com> wrote:

Quote:
I have been away from this for a long time and seem to have forgotten
much of which I learned. This syntax will always only ever return one
record and I need to use the value returned in the column
"IPT_Rates.IPT_Percentage". What am I missing? Is the use of
"Column() if so where?
Thanks in advance from one frustrated brain dead amateur.

Dim iptCurrent As String

iptCurrent = "SELECT IPT_Rates.IPT_Percentage,
IPT_Rates.IPT_RateChangeStartDate, IPT_Rates.IPT_RateChangeFinish " _
& "FROM IPT_Rates " _ & "GROUP BY IPT_Rates.IPT_Percentage,
IPT_Rates.IPT_RateChangeStartDate, IPT_Rates.IPT_RateChangeFinish " _
& "HAVING (((IPT_Rates.IPT_RateChangeStartDate)<=([Forms]![frmPolicy]!
[txtPeriodStartDate])) " _
& "AND ((IPT_Rates.IPT_RateChangeFinish)>=([Forms]![frmPolicy]!
[txtPeriodStartDate])));"
Hi Colin,

If you only need to return one column, you should only specify one
column. So the query should read:

SELECT IPT_Rates.IPT_Percentage
FROM (...rest of query unchanged)

Based on your total description, I think you can also simplify the
query. You should test, of course, but I expect that the query below
is equivalent:

SELECT DISTINCT IPT_Percentage
FROM IPT_Rates
WHERE [Forms]![frmPolicy]![txtPeriodStartDate]
BETWEEN IPT_RateChangeStartDate
AND IPT_RateChangeFinish;

You probably don't need the DISTINCT either, but that's impossible for
me to tell with the info you gave. Remove it if you can, as the query
will probably be faster without this keyword.
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

Reply With Quote
  #3  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Simple Query - I need to select the value from one column - 11-03-2010 , 08:46 AM



On Nov 3, 9:09*am, colin spalding <colin.mard... (AT) btopenworld (DOT) com>
wrote:
Quote:
I have been away from this for a long time and seem to have forgotten
much of which I learned. *This syntax will always only ever return one
record and I need to use the value returned in the column
"IPT_Rates.IPT_Percentage". *What am I missing? *Is the use of
"Column() if so where?
Thanks in advance from one frustrated brain dead amateur.

Dim iptCurrent As String

iptCurrent = "SELECT IPT_Rates.IPT_Percentage,
IPT_Rates.IPT_RateChangeStartDate, IPT_Rates.IPT_RateChangeFinish " _
& "FROM IPT_Rates " _ & "GROUP BY IPT_Rates.IPT_Percentage,
IPT_Rates.IPT_RateChangeStartDate, IPT_Rates.IPT_RateChangeFinish " _
& "HAVING (((IPT_Rates.IPT_RateChangeStartDate)<=([Forms]![frmPolicy]!
[txtPeriodStartDate])) " _
& "AND ((IPT_Rates.IPT_RateChangeFinish)>=([Forms]![frmPolicy]!
[txtPeriodStartDate])));"
I am not even sure what your question is, but generally for this type
of question you need to specify what language and tool version the
code is in and post the actual error message. I am not even sure if
you have a compile type error or a run-time error. The database
version is also usually important information.

HTH -- Mark D Powell --

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.