Monday, March 26, 2012

query

Hi, I have a query to build a returned record as and order by Name:
ID, Name
5 A
1 B
3 C '?
4 D
2 E
Now, I want to add a parameter (for example ID=3) to the query (or somehow),
so the returned record only return:
ID, Name
4 D
2 E
How to do that? Thanks.Please post the text of your query, then I will have my worker bees make the
changes you request.|||Try,
select [id], [name]
from t1
where [id] > 3
order by [name]
AMB
"js" wrote:

> Hi, I have a query to build a returned record as and order by Name:
> ID, Name
> 5 A
> 1 B
> 3 C '?
> 4 D
> 2 E
>
> Now, I want to add a parameter (for example ID=3) to the query (or somehow
),
> so the returned record only return:
> ID, Name
> 4 D
> 2 E
>
> How to do that? Thanks.
>
>|||Add a WHERE clause to your query. It is possible to create a stored
procedure which accepts a parameter. The stored procedure would return data
just as your query does.
Keith
"js" <js@.someone@.hotmail.com> wrote in message
news:e1O1SpATFHA.3056@.TK2MSFTNGP14.phx.gbl...
> Hi, I have a query to build a returned record as and order by Name:
> ID, Name
> 5 A
> 1 B
> 3 C '?
> 4 D
> 2 E
>
> Now, I want to add a parameter (for example ID=3) to the query (or
> somehow), so the returned record only return:
> ID, Name
> 4 D
> 2 E
>
> How to do that? Thanks.
>
>|||Thanks...
Add a WHERE clause(where [id] > 3) to query will filter out (2, E)?
select [id], [name]
from t1
where [id] > 3
order by [name]
"Keith Kratochvil" <sqlguy.back2u@.comcast.net> wrote in message
news:O1uUovATFHA.2996@.TK2MSFTNGP15.phx.gbl...
> Add a WHERE clause to your query. It is possible to create a stored
> procedure which accepts a parameter. The stored procedure would return
> data just as your query does.
> --
> Keith
>
> "js" <js@.someone@.hotmail.com> wrote in message
> news:e1O1SpATFHA.3056@.TK2MSFTNGP14.phx.gbl...
>|||One solution would be:
Select T.Id, T.Name
From Table As T
Where Ascii(T.Name) > Ascii('C')
Another would be
Select T.Id, T.Name
From Table As T
Where Cast(T.Name As Binary(1)) > Cast('C' As Binary(1))
Of course, by doing it this way, you'll likely get an index or table scan.
Thomas
"js" <js@.someone@.hotmail.com> wrote in message
news:e1O1SpATFHA.3056@.TK2MSFTNGP14.phx.gbl...
> Hi, I have a query to build a returned record as and order by Name:
> ID, Name
> 5 A
> 1 B
> 3 C '?
> 4 D
> 2 E
>
> Now, I want to add a parameter (for example ID=3) to the query (or somehow
),
> so the returned record only return:
> ID, Name
> 4 D
> 2 E
>
> How to do that? Thanks.
>
>|||Actually, SQL as I just discovered, SQL is smart enough to do this sort of
analysis on strings for you. So you should be able to do this:
Select T.Id, T.Name
From Table As T
Where T.Name > 'C'
Thomas
"Thomas Coleman" <replyingroup@.anywhere.com> wrote in message
news:%23CLAj9ATFHA.3036@.TK2MSFTNGP10.phx.gbl...
> One solution would be:
> Select T.Id, T.Name
> From Table As T
> Where Ascii(T.Name) > Ascii('C')
> Another would be
> Select T.Id, T.Name
> From Table As T
> Where Cast(T.Name As Binary(1)) > Cast('C' As Binary(1))
> Of course, by doing it this way, you'll likely get an index or table scan.
>
> Thomas
>
> "js" <js@.someone@.hotmail.com> wrote in message
> news:e1O1SpATFHA.3056@.TK2MSFTNGP14.phx.gbl...
>|||Thanks Thomas,
I don't know 'C' but only "ID=3"

Query:
select [id], [name] from tb1
union
select [id], [name] from tb2
union
select [id], [name] from tb3
ORDER BY [name]
Output:
How to return this base the previous query:
Can I use a cursor in sql:
dim rs
sql0= "DECLARE TBs_Cursor CURSOR FOR "
sql1 = "select [id], [name] from tb1 union select [id], [name] from tb2
union select [id], [name] from tb3 ORDER BY [name]"
sql2 = sql0 + sql1 + 'OPEN Cursor, Loop if ID < 3, then delete, and return
the records'
rs.open sql2,...
"Thomas Coleman" <replyingroup@.anywhere.com> wrote in message
news:%23CLAj9ATFHA.3036@.TK2MSFTNGP10.phx.gbl...
> One solution would be:
> Select T.Id, T.Name
> From Table As T
> Where Ascii(T.Name) > Ascii('C')
> Another would be
> Select T.Id, T.Name
> From Table As T
> Where Cast(T.Name As Binary(1)) > Cast('C' As Binary(1))
> Of course, by doing it this way, you'll likely get an index or table scan.
>
> Thomas
>
> "js" <js@.someone@.hotmail.com> wrote in message
> news:e1O1SpATFHA.3056@.TK2MSFTNGP14.phx.gbl...
>|||On Thu, 28 Apr 2005 11:52:44 -0400, "js" <js@.someone@.hotmail.com> wrote:

>Hi, I have a query to build a returned record as and order by Name:
>ID, Name
>5 A
>1 B
>3 C '?
>4 D
>2 E
>
>Now, I want to add a parameter (for example ID=3) to the query (or somehow)
,
>so the returned record only return:
>ID, Name
>4 D
>2 E
>
>How to do that? Thanks.
>
Hi js,
Try if this does what you want:
SELECT ID, Name
FROM MyTable
WHERE Name > (SELECT Name
FROM MyTable
WHERE Id = 3)
ORDER BY Name
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||> I don't know 'C' but only "ID=3"
Not sure what you mean here.
Thomas

No comments:

Post a Comment