Select Query

Feb 27, 2007

Hi, I'm trying to do the following select statement.

I have the following databases with the following tables and columns which will be involved with the query.

DataBase Name: users
Table: Users
Column: UserName
Column: UserId

DataBase Name: documentareas
Table: document_area
Column: doc_area_id
Column: doc_area_name
Column: doc_area_type
Column: doc_area_default
Table: document_area_user_access
Column: doc_area (contains a doc_area_id)
Column: user_id (contains a username)

Now I want to select the doc_area_name where the logged in username exists in the user_id of the document_area_user_access table.

So to clarify, I am looking to look through the document_area_user_access for each time the current users username exists and for each existing username the doc_area_name is displayed depending on what doc_area(s) is associated with the user_id in document_area_user_access.

Don't know if this has made any sense??

I am hoping to do all this in the aspx sqlsource if possible. As for each userarea that the user has access a link will exist.

Cheers, Mark

View 5 Replies


ADVERTISEMENT

Return The Results Of A Select Query In A Column Of Another Select Query.

Feb 8, 2008

Not sure if this is possible, but maybe. I have a table that contains a bunch of logs.
I'm doing something like SELECT * FROM LOGS. The primary key in this table is LogID.
I have another table that contains error messages. Each LogID could have multiple error messages associated with it. To get the error messages.
When I perform my first select query listed above, I would like one of the columns to be populated with ALL the error messages for that particular LogID (SELECT * FROM ERRORS WHERE LogID = MyLogID).
Any thoughts as to how I could accomplish such a daring feat?

View 9 Replies View Related

Select Query Based Upon Results Of Another Select Query??

Sep 6, 2006

Hi, not exactly too sure if this can be done but I have a need to run a query which will return a list of values from 1 column. Then I need to iterate this list to produce the resultset for return.
This is implemented as a stored procedure

declare @OwnerIdent varchar(7)
set @OwnerIdent='A12345B'

SELECT table1.val1 FROM table1 INNER JOIN table2
ON table1. Ident = table2.Ident
WHERE table2.Ident = @OwnerIdent

'Now for each result of the above I need to run the below query

SELECT Clients.Name , Clients.Address1 ,
Clients.BPhone, Clients.email
FROM Clients INNER JOIN Growers ON Clients.ClientKey = Growers.ClientKey
WHERE Growers.PIN = @newpin)

'@newpin being the result from first query

Any help appreciated

View 4 Replies View Related

Result Sets Using Select In Query Anlyzer Vs BCP Vs Select Into

Jul 9, 2002

When I run simple select against my view in Query Analyzer, I get result set in one sort order. The sort order differs, when I BCP the same view. Using third technique i.e. Select Into, I have observed the sort order is again different in the resulting table. My question is what is the difference in mechanisim of query analyzer, bcp, and select into.
Thanks

View 1 Replies View Related

Date Select Query - Select Between Two Dates

Aug 22, 2006

have a table with students details in it, i want to select all the students who joined a class on a particular day and then i need another query to select all students who joined classes over the course of date range eg 03/12/2003 to 12/12/2003.

i have tried with the following query, i need help putting my queries together
select * from tblstudents where classID='1' and studentstartdate between ('03/12/2004') and ('03/12/2004')

when i run this query i get this message

Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

the studentstartdate field is set as datetime 8 and the date looks like this in the table 03/12/2004 03:12:15

please help
mustfa

View 6 Replies View Related

SQL Server 2012 :: Adding Count To Query Without Duplicating Original Select Query

Aug 5, 2014

I have the following code.

SELECT _bvSerialMasterFull.SerialNumber, _bvSerialMasterFull.SNStockLink, _bvSerialMasterFull.SNDateLMove, _bvSerialMasterFull.CurrentLoc,
_bvSerialMasterFull.CurrentAccLink, _bvSerialMasterFull.StockCode, _bvSerialMasterFull.CurrentAccount, _bvSerialMasterFull.CurrentLocationDesc,
_bvSerialNumbersFull.SNTxDate, _bvSerialNumbersFull.SNTxReference, _bvSerialNumbersFull.SNTrCodeID, _bvSerialNumbersFull.SNTransType,
_bvSerialNumbersFull.SNWarehouseID, _bvSerialNumbersFull.TransAccount, _bvSerialNumbersFull.TransTypeDesc,

[code]...

However, as you can see, the original select query is run twice and joined together.What I was hoping for is this to be done in the original query without the need to duplicate the original query.

View 2 Replies View Related

SQL Server 2012 :: How To Pull Value Of Query And Not Value Of Variable When Query Using Select Top 1 Value From Table

Jun 26, 2015

how do I get the variables in the cursor, set statement, to NOT update the temp table with the value of the variable ? I want it to pull a date, not the column name stored in the variable...

create table #temptable (columname varchar(150), columnheader varchar(150), earliestdate varchar(120), mostrecentdate varchar(120))
insert into #temptable
SELECT ColumnName, headername, '', '' FROM eddsdbo.[ArtifactViewField] WHERE ItemListType = 'DateTime' AND ArtifactTypeID = 10
--column name
declare @cname varchar(30)

[code]...

View 4 Replies View Related

Transact SQL :: Use Query Results As Select Criteria For Another Query

Jul 10, 2015

I have a query that performs a comparison between 2 different databases and returns the results of the comparison. It returns 2 columns. The 1st column is the value of the object being compared, and the 2nd column is a number representing any discrepancies.What I would like to do is use the results from this 1st query in the where clause of another separate query so that this 2nd query will only run for any primary values from the 1st query where a secondary value in the 1st query is not equal to zero.I was thinking of using an "IN" function in the 2nd query to pull data from the 1st column in the 1st query where the 2nd column in the 1st query != 0, but I'm having trouble ironing out the correct syntax, and conceptualizing this optimally.

While I would prefer to only return values from the 1st query where the comparison value != 0 in order to have a concise list to work with, I am having difficulty in that the comparison value is a mathematical calculation of 2 different tables in 2 different databases, and so far I've been forced to include it in the select criteria because the where clause does not accept it.Also, I am not a DBA by trade. I am a system administrator writing SQL code for reporting data from an application I support.

View 6 Replies View Related

Transact SQL :: SELECT On Column Name From Query Result Set In Same Query?

May 9, 2015

I have a column colC in a table myTable that has a value (e.g. '0X'). The position of a non-zero character in column colC refers to the ordinal position of another column in the table myTable (in the aforementioned example, colB).

To get a column name (i.e., colA or colB) from table myTable, I can join ("ON cte.pos = cn.ORDINAL_POSITION") to INFORMATION_SCHEMA.COLUMNS for that table catalog, schema and name. But I want to show the value of what is in that column (e.g., 'ABC'), not just the name. Hoping for:

COLUMN_NAME Value
----------- -----
colB        123
colA        XYZ

I've tried dynamic SQL to no success, probably not executing the concept correctly...

Below is what I have:

CREATE TABLE myTable (colA VARCHAR(3), colB VARCHAR(3), colC VARCHAR(3))
INSERT INTO myTable (colA, colB, colC) VALUES ('ABC', '123', '0X')
INSERT INTO myTable (colA, colB, colC) VALUES ('XYZ', '789', 'X0')
;WITH cte AS
(
SELECT CAST(PATINDEX('%[^0]%', colC) AS SMALLINT) pos, STUFF(colC, 1, PATINDEX('%[^0]%', colC), '') colC

[Code] ....

View 4 Replies View Related

Declaring A Table Variable Within A Select Table Joined To Other Select Tables In Query

Oct 15, 2007

Hello,

I hope someone can answer this, I'm not even sure where to start looking for documentation on this. The SQL query I'm referencing is included at the bottom of this post.

I have a query with 3 select statements joined together like tables. It works great, except for the fact that I need to declare a variable and make it a table within two of those 3. The example is below. You'll see that I have three select statements made into tables A, B, and C, and that table A has a variable @years, which is a table.

This works when I just run table A by itself, but when I execute the entire query, I get an error about the "declare" keyword, and then some other errors near the word "as" and the ")" character. These are some of those errors that I find pretty meaningless that just mean I've really thrown something off.

So, am I not allowed to declare a variable within these SELECT tables that I'm creating and joining?

Thanks in advance,
Andy



Select * from

(

declare @years table (years int);

insert into @years

select

CASE

WHEN month(getdate()) in (1) THEN year(getdate())-1

WHEN month(getdate()) in (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) THEN year(getdate())

END

select

u.fullname

, sum(tx.Dm_Time) LastMonthBillhours

, sum(tx.Dm_Time)/((select dm_billabledays from dm_billabledays where Dm_Month = Month(GetDate()))*8) lasmosbillingpercentage

from

Dm_TimeEntry tx

join

systemuserbase u

on

(tx.owninguser = u.systemuserid)

where

Month(tx.Dm_Date) = Month(getdate())-1

and

year(dm_date) = (select years from @years)

and tx.dm_billable = 1

group by u.fullname

) as A

left outer join

(select

u.FullName

, sum(tx.Dm_Time) Billhours

, ((sum(tx.Dm_Time))

/

((day(getdate()) * ((5.0)/(7.0))) * 8)) perc

from

Dm_TimeEntry tx

join

systemuserbase u

on

(tx.owninguser = u.systemuserid)

where

tx.Dm_Billable = '1'

and

month(tx.Dm_Date) = month(GetDate())

and

year(tx.Dm_Date) = year(GetDate())

group by u.fullname) as B

on

A.Fullname = B.Fullname

Left Outer Join

(

select

u.fullname

, sum(tx.Dm_Time) TwomosagoBillhours

, sum(tx.Dm_Time)/((select dm_billabledays from dm_billabledays where Dm_Month = Month(GetDate()))*8) twomosagobillingpercentage

from

Dm_TimeEntry tx

join

systemuserbase u

on

(tx.owninguser = u.systemuserid)

where

Month(tx.Dm_Date) = Month(getdate())-2

group by u.fullname

) as C

on

A.Fullname = C.Fullname

View 1 Replies View Related

Select Query Vs Store Procedure Query

Oct 29, 1998

hi, does it make a difference to write the following select statement in either query window or create a sp and then calling the store procedure to be executed..

select * from authors

OR


create procedure authors as

select * from authors





lets assume that we have million records in the author table. is it faster to run the query from within a store procedure or not ?
thanks for your input

Ali

View 1 Replies View Related

Select Statement Within Select Statement Makes My Query Slow....

Sep 3, 2007

Hello... im having a problem with my query optimization....

I have a query that looks like this:


SELECT * FROM table1
WHERE location_id IN (SELECT location_id from location_table WHERE account_id = 998)


it produces my desired data but it takes 3 minutes to run the query... is there any way to make this faster?... thank you so much...

View 3 Replies View Related

How To Remove Partially Duplicate Rows From Select Query's Result Set (DB Schema Provided And Query Provided).

Jan 28, 2008

Hi, 
Please help me with an SQL Query that fetches all the records from the three tables but a unique record for each forum and topicid with the maximum lastpostdate. I have to bind the result to a GridView.Please provide separate solutions for SqlServer2000/2005. 
I have three tables namely – Forums,Topics and Threads  in SQL Server2000 (scripts for table creation and insertion of test data given at the end). Now, I have formulated a query as below :- 
SELECT ALL f.forumid,t.topicid,t.name,th.author,th.lastpostdate,(select count(threadid) from threads where topicid=t.topicid) as NoOfThreads
FROM
Forums f FULL JOIN Topics t ON f.forumid=t.forumid
FULL JOIN Threads th ON t.topicid=th.topicid
GROUP BY t.topicid,f.forumid,t.name,th.author,th.lastpostdate
ORDER BY t.topicid ASC,th.lastpostdate DESC 
Whose result set is as below:- 




forumid
topicid
name
author
lastpostdate
NoOfThreads

1
1
Java Overall
x@y.com
2008-01-27 14:48:53.000
2

1
1
Java Overall
a@b.com
2008-01-27 14:44:29.000
2

1
2
JSP
NULL
NULL
0

1
3
EJB
NULL
NULL
0

1
4
Swings
p@q.com
2008-01-27 15:12:51.000
1

1
5
AWT
NULL
NULL
0

1
6
Web Services
NULL
NULL
0

1
7
JMS
NULL
NULL
0

1
8
XML,HTML
NULL
NULL
0

1
9
Javascript
NULL
NULL
0

2
10
Oracle
NULL
NULL
0

2
11
Sql Server
NULL
NULL
0

2
12
MySQL
NULL
NULL
0

3
13
CSS
NULL
NULL
0

3
14
FLASH/DHTLML
NULL
NULL
0

4
15
Best Practices
NULL
NULL
0

4
16
Longue
NULL
NULL
0

5
17
General
NULL
NULL
0  
On modifying the query to:- 
SELECT ALL f.forumid,t.topicid,t.name,th.author,th.lastpostdate,(select count(threadid) from threads where topicid=t.topicid) as NoOfThreads
FROM
Forums f FULL JOIN Topics t ON f.forumid=t.forumid
FULL JOIN Threads th ON t.topicid=th.topicid
GROUP BY t.topicid,f.forumid,t.name,th.author,th.lastpostdate
HAVING th.lastpostdate=(select max(lastpostdate)from threads where topicid=t.topicid)
ORDER BY t.topicid ASC,th.lastpostdate DESC 
I get the result set as below:- 




forumid
topicid
name
author
lastpostdate
NoOfThreads

1
1
Java Overall
x@y.com
2008-01-27 14:48:53.000
2

1
4
Swings
p@q.com
2008-01-27 15:12:51.000

I want the result set as follows:- 




forumid
topicid
name
author
lastpostdate
NoOfThreads

1
1
Java Overall
x@y.com
2008-01-27 14:48:53.000
2

1
2
JSP
NULL
NULL
0

1
3
EJB
NULL
NULL
0

1
4
Swings
p@q.com
2008-01-27 15:12:51.000
1

1
5
AWT
NULL
NULL
0

1
6
Web Services
NULL
NULL
0

1
7
JMS
NULL
NULL
0

1
8
XML,HTML
NULL
NULL
0

1
9
Javascript
NULL
NULL
0

2
10
Oracle
NULL
NULL
0

2
11
Sql Server
NULL
NULL
0

2
12
MySQL
NULL
NULL
0

3
13
CSS
NULL
NULL
0

3
14
FLASH/DHTLML
NULL
NULL
0

4
15
Best Practices
NULL
NULL
0

4
16
Longue
NULL
NULL
0

5
17
General
NULL
NULL
0  I want all the rows from the Forums,Topics and Threads table and the row with the maximum date (the last post date of the thread) as shown above. 
The scripts for creating the tables and inserting test data is as follows in an already created database:- 
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__Topics__forumid__79A81403]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Topics] DROP CONSTRAINT FK__Topics__forumid__79A81403
GO 
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__Threads__topicid__7C8480AE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Threads] DROP CONSTRAINT FK__Threads__topicid__7C8480AE
GO 
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Forums]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Forums]
GO 
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Threads]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Threads]
GO 
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Topics]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Topics]
GO 
CREATE TABLE [dbo].[Forums] (
            [forumid] [int] IDENTITY (1, 1) NOT NULL ,
            [name] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
            [description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO 
CREATE TABLE [dbo].[Threads] (
            [threadid] [int] IDENTITY (1, 1) NOT NULL ,
            [topicid] [int] NOT NULL ,
            [subject] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
            [replies] [int] NOT NULL ,
            [author] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
            [lastpostdate] [datetime] NULL
) ON [PRIMARY]
GO 
CREATE TABLE [dbo].[Topics] (
            [topicid] [int] IDENTITY (1, 1) NOT NULL ,
            [forumid] [int] NULL ,
            [name] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
            [description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO 
ALTER TABLE [dbo].[Forums] ADD
             PRIMARY KEY  CLUSTERED
            (
                        [forumid]
            )  ON [PRIMARY]
GO 
ALTER TABLE [dbo].[Threads] ADD
             PRIMARY KEY  CLUSTERED
            (
                        [threadid]
            )  ON [PRIMARY]
GO 
ALTER TABLE [dbo].[Topics] ADD
             PRIMARY KEY  CLUSTERED
            (
                        [topicid]
            )  ON [PRIMARY]
GO  
ALTER TABLE [dbo].[Threads] ADD
             FOREIGN KEY
            (
                        [topicid]
            ) REFERENCES [dbo].[Topics] (
                        [topicid]
            )
GO 
ALTER TABLE [dbo].[Topics] ADD
             FOREIGN KEY
            (
                        [forumid]
            ) REFERENCES [dbo].[Forums] (
                        [forumid]
            )
GO  
------------------------------------------------------ 
insert into forums(name,description) values('Developers','Developers Forum');
insert into forums(name,description) values('Database','Database Forum');
insert into forums(name,description) values('Desginers','Designers Forum');
insert into forums(name,description) values('Architects','Architects Forum');
insert into forums(name,description) values('General','General Forum'); 
insert into topics(forumid,name,description) values(1,'Java Overall','Topic Java Overall');
insert into topics(forumid,name,description) values(1,'JSP','Topic JSP');
insert into topics(forumid,name,description) values(1,'EJB','Topic Enterprise Java Beans');
insert into topics(forumid,name,description) values(1,'Swings','Topic Swings');
insert into topics(forumid,name,description) values(1,'AWT','Topic AWT');
insert into topics(forumid,name,description) values(1,'Web Services','Topic Web Services');
insert into topics(forumid,name,description) values(1,'JMS','Topic JMS');
insert into topics(forumid,name,description) values(1,'XML,HTML','XML/HTML');
insert into topics(forumid,name,description) values(1,'Javascript','Javascript');
insert into topics(forumid,name,description) values(2,'Oracle','Topic Oracle');
insert into topics(forumid,name,description) values(2,'Sql Server','Sql Server');
insert into topics(forumid,name,description) values(2,'MySQL','Topic MySQL');
insert into topics(forumid,name,description) values(3,'CSS','Topic CSS');
insert into topics(forumid,name,description) values(3,'FLASH/DHTLML','Topic FLASH/DHTLML');
insert into topics(forumid,name,description) values(4,'Best Practices','Best Practices');
insert into topics(forumid,name,description) values(4,'Longue','Longue');
insert into topics(forumid,name,description) values(5,'General','General Discussion'); 
insert into threads(topicid,subject,replies,author,lastpostdate) values (1,'About Java Tutorial',2,'a@b.com','1/27/2008 02:44:29 PM');
insert into threads(topicid,subject,replies,author,lastpostdate) values (1,'Java Basics',0,'x@y.com','1/27/2008 02:48:53 PM');
insert into threads(topicid,subject,replies,author,lastpostdate) values (4,'Swings',0,'p@q.com','1/27/2008 03:12:51 PM');
 

View 7 Replies View Related

SQL SELECT Query

Nov 21, 2006

Hi,

I have been having problems trying to sort this query out and would appreciate some pointers.

I have a SQL Server table 'Match' which includes the columns:

match_date    datetime
age_group    int


The match_date column includes both date and time values. The age_group column is an id linked to an 'Age_Group' table.


I would like the select query to retrieve the top 3 dates (not including times) and the agegroups for these dates.


For example:

The table data might include

match_date, agegroup
--------------------
10/11/2006 10:00, 1
10/11/2006 11:00, 1
10/11/2006 12:00, 1
10/11/2006 13:00, 2
03/11/2006 09:00, 3
03/11/2006 10:00, 4
03/11/2006 11:00, 5
25/10/2006 10:00, 2
20/09/2006 10:00, 5
20/09/2006 10:00, 6


I would like the SELECT to retrieve like so:


match_date, agegroup
--------------------
10/11/2006, 1
10/11/2006, 2
03/11/2006, 3
03/11/2006, 4
03/11/2006, 5
25/10/2006, 2


So the query only returns the one record for each age_group on each date for the top 3 dates.
Does anyone have any ideas? I hope I have explained it well enough!

Thanks,
Pete

View 2 Replies View Related

SELECT Query

Apr 3, 2007

 Hello,I have the following tables:[Blogs] > BlogId (PK), ...[Posts] > PostId (PK), BlogId (FK), Title, Content, ...[Labels] > LabelId (PK), LabelName[LabelsInPosts] > LabelId (PK), PostId(PK)I am selecting all posts from a Blog given the BlogId:SELECT * FROM dbo.Posts WHERE BlogId = @BlogIdThis will return the columns Title, Content, ... for those posts.I would like to add 2 columns, PostLabels and LabelsCount:1. PostLabels would be created by:For each post select all the labels associated with it inLabelsInPosts. Then for each label get the label name. Then createthe value of PostLabels which would be each label separated by acomma.I tried the following but this is not working. I am having problems getting the LabelId from LabelsInPosts and then getting the LabelName from Labels and use them to create the CSV string:SELECT DISTINCT    l1.PostID,        STUFF((SELECT DISTINCT TOP 100 PERCENT ',' + l2.LabelName FROM Labels AS l2 WHERE l2.PostID = l1.PostID ORDER BY ',' + l2.LabelName FOR XML PATH('')), 1, 1, '') AS PostLabelsFROM        Labels AS l1ORDER BY    l1.PostID2. LabelsCount would be the number of labels associated with each postI created a procedure which, given a PostId, returns the number oflabels associated with it.So I suppose it would be only a question of integrating a call tothis procedure with this SELECT I am trying to create.Thank You,Miguel

View 2 Replies View Related

Select Query Help

Apr 11, 2007

I need to query the DB and only see if the 1st 5 characters of a Guid match. How would i go about only calling a certain amount of characters from a Guid?

View 11 Replies View Related

Select Query

Aug 26, 2007

i have a table which has a colum name's Name, Album.
the way data is storing is for
Name  Album
 '123'    'xyz'
'4555'  'xyz'
''212'    'xyz'
'33sa'  'abc'
'nyz1'  'abc'    and so on.
what would be the query for selecting all the Album's one row only.
like when i write the query i want it to return like this.
'xyz'
'abc'   

View 2 Replies View Related

Select Query

Apr 12, 2008

I have a table as below after executing select query  select userid as userid,count as totalcount from table1
UserId totalcount
101       15
102         7 
105         6
106         4
108         3
i want a extra column so that it is an autoincrement and the query result should be like
UserId totalcount Sno
101       15            1
102         7            2
105         6            3
106         4            4
 
 
 

View 1 Replies View Related

Select Query ?

Apr 25, 2008

 hi friends......            i have table t1 task                      startdate                             enddate 1                            03/04/2008                           10/04/2008 2                            04/04/2008                            10/04/20083                              06/04/2008                           25/04/2008 i need a query to get task id and  column2column2 = if(enddate > getdate()) then 1 else 2  give me the answer without the use of cursors......answer should be in a query...thanks in advance       

View 5 Replies View Related

Use Value From Select Query

Apr 28, 2008

I am writing to learn if it is possible to obtain a value from a select query, and utilize this value in a succeeding query.
Please see below for my current query.  I would like to take the filenum result, and use the value in a second query.
Thanks in advance! 
select shhd.CUST_NO, shhd.file_no as filenum from tpsdba.shipment_header SHHD WHERE SHHD.CUST_NO = '052584 ' AND (SHHD.DATE_ENTRY >= '20080401' AND SHHD.DATE_ENTRY <= '20080404') 
 

View 2 Replies View Related

Help With Select Top X Query

May 10, 2008

im trying to get a page to display this query like this in a data grid
SELECT TOP @rows * FROM students
where student_id = @studentID
Basically I want code that returns the top X number of rows, where X is a user defined variable (like in a textbox)... I've been trying to find a way to get this to work and have not and any luck... any ideas?
 
thanks!

View 1 Replies View Related

Select Query

Jun 19, 2008

Hello All
I havetable with 2 columns  and Datas like this
LRNo              LRStatus
L001                10
L002                10
L003                10
L001                15
L002                15
L001                20
i need a query to select the LRNo where lrstatus =10 and not equal to 15 and 20
here is my query
select lrno from tbl where lrstatus in (10) and not in (15.20)
but i didnt get it
 Please help me
Thanks in Advance
 

View 6 Replies View Related

Help On A Select Query

Dec 11, 2003

HI all,


SELECT @PmtId = PmtId
FROM EmpStatus WHERE
PmtStatusDt = @PmtStatusDt AND (PmtStatusCd= 'T' OR PmtStatusCd='X' )

SELECT PmtID, PmtBalanceCd, SUM (EmpPmtBalanceAmt)
FROM Emp_Pmt_Balance WHERE PmtId = @PmtId
GROUP BY PmtBalanceCd

But my problem here is this that:
My PmtID can be multiple records. example of the tables is as below

EmpStatus
--------------

PmtId PmtStatusDt PmtStatusCd

1 12/11/03 T
2 12/11/03 X
3 12/11/03 T


Emp_Pmt_Balance
-------------------

PmtId PmtBalanceCd EmpPmtBalanceAmt
1 560 12.00
1 562 13.00
2 560 24.00
2 562 28.00
3 560 34.00 3 562 28.00


The expected result:

PmtBalanceCd EmpPmtBalanceAmt
560 70.00
562 69 .00

Any help to get this tuff working is appreciated.

View 3 Replies View Related

Select Query

Dec 12, 2003

I have a select query on the table as

SELECT PmtId FROM Emp_Pmt_Status WHERE
PmtStatusDt > = '12/9/2003' AND
(PmtStatusCd= 'T' OR PmtStatusCd='X' ) Order By PmtStatusDt

This returns:

PmtId PmtStatusDt
---- ________________
1 12/9/2003
2 12/10/2003
3 12/10/2003
4 12/11/2003
5 12/12/2003

Now I have another table :
Emp_Pmt_Balance
-------------------

PmtId PmtBalanceCd EmpPmtBalanceAmt
____________________________________________________________________________________
1 560 12.00
1 562 13.00
2 560 24.00
2 562 28.00
3 560 34.00
3 562 28.00
4 560 24.00
4 562 28.00
5 560 34.00
5 562 28.00

But the results should be

PmtBalanceCd EmpPmtBalanceAmt
_________________________________________________________________________________


560 (for PmtId =1 ) 12.00
562 (for PmtId =1 ) 13.00
560 (for PmtId =2 ,3) 58.00
562 (for PmtId =2 ,3) 56.00
560 (for PmtId =4) 24.00
562 (for PmtId =4) 28.00
560 (for PmtId =5) 34.00
562 (for PmtId =5) 28.00


This expected results are based on the date. Sum up (EmpPmtBalanceAmt) for similar PmtBalanceCd if the date for the pmtid's are same.

What should be the select query to get the above result.
Any help is highly appreciated.
Thanks

View 1 Replies View Related

Select Query

Jan 7, 2004

I have a Table:

Name | Sal
---------------------------------
A | 2
B | 2
A | 1

I have a select query with a group by like:

Select Name, SUM(sal) from table Group By Name

Name | sal
----------------------------
A | 3
B | 2

How do I write a select query for getting the result like:-

Name | sal
---------------------------------
A | 5
B | 5

the 5 in the sal column should be the sum of the group By done in the first select statement.

Plz help

View 3 Replies View Related

Select Query.....?

Feb 11, 2004

I just want to concatenate two dates in Select query.
For example I've 2 fields- fromdate and todate in a database table and i just want to join them by a dash.

How could I do this?
I'm using SQL server 2000

Thanks and Regards.

View 3 Replies View Related

Need Help With SELECT Query...

Aug 28, 2004

--Previously posted on Access Forum w/o response--

Hi,

I have 3 tables in my database:

tbl_ing - Ing_ID, Ingredients
tbl_items - Items
tbl_recipes - Recipe_Name, Ing_ID

tbl_recipes contains recipe names and is directly linked to tbl_ing, which hold all ingredients for the recipes, so for example tbl_recipes may have a recipe named "Bread" and a ing_ID of "23". In the tbl_ing table there would be (flour)(23), (water)(23), (salt)(23), (yeast)(23). Each parantheses represents a column in each row.

I have no problem to link those 2 tables together and display the results on a webpage, but I want to go a step further with my 3rd table. tbl_items contains several ingredients without any relationship to any other table. They contents of that table changes frequently. It's basically a list of available ingredients at any given moment.

I want to be able to display all the recipes I could make with the available ingredients in the tbl_items table.
So, let's say I have flour, water, salt, yeast, sugar, apples in the tbl_items table. In the tbl_recipes table I have Bread, Applepie and Cherrypie. With my available ingredients I can make bread and the applepie, but not the cherrypie.
Now I need to write a query that will display only those matching recipes. I'm lost on this. Can anyone please help me?

Thank you!

View 2 Replies View Related

Help With Select Query

May 4, 2005

This should be simple I think but I am no expert so maybe one of you will have the kindness to help me a bit.  I have two tables(System, NAIC) and both have the primary key SystemId.
I need to gell all the rows from the table system and anything that correspond from the table NAIC, if no correspondant systemId the return "" or nothing in the fields of NAIC
Thank you,
Table: System-SystemId*-Company-Reseller-SystemType...
NAIC-SystemId*-NAIC_1-NAIC_2-NAIC_3-NAIC_4

View 1 Replies View Related

Help In Select Query

Nov 11, 2005

In an inventory database I have a table of Items: Item_ID, Item_Name, Current_Qtyanother table called In_Stock which records the deposits made to each item: ID, Date,Item_ID, Qtyand another called Out_Stock which records the withdraws made from each itemID, Date,Item_ID, QtyIf I want to know how many unit are there now from a specific item , I get the value of Current_Qty in the Items table.My problem is that I need to know how many units were on stock in a specific period from date1 to date2 , I failed to write a select query for the required data.Any help please?Thanks.

View 4 Replies View Related

SQL Query: Select * Where X=everything??

Mar 9, 2006

I've got a DataGrid that displays results depending on a selection in a dropdown list. So far, so good.But I'd also like to have an option in the dropdown list that permits to display ALL the results. The query used to fill the datagrid is the following: "SELECT * FROM [tSpecies] WHERE ([Status] = @Status)"The @Status variable refers to the selected value in the dropdown list. Which value would be needed so that this WHERE clause would display ALL the records?Thanks a lot!

View 1 Replies View Related

Going Over 2 Select's In 1 Query

Apr 20, 2006

i have a code L;conPubs = New SqlConnection(conStr)
conPubs.Open()
'**>> building select box for מצב המסלול

cmdSelect = New SqlCommand("Select * From course_type;SELECT UploadTrail_id, UploadTrail_select_types_id FROM UploadTrail_select_values WHERE (UploadTrail_id = 54) AND (UploadTrail_select_types_id = 6);", conPubs)
Dim Reader As SqlDataReader
Reader = cmdSelect.ExecuteReader()
course_type.DataSource = Reader
course_type.DataValueField = "course_id"
course_type.DataTextField = "course_name"
course_type.DataBind() 
if u look u will see 2 select's that are delimited with ; (semicolon)how can i access the second recordset after i bind the first one on the last line (i want to get values from the rows in the second "select")thnaks in advancepeleg 

View 1 Replies View Related

HELP!! SELECT QUERY

Nov 21, 2001

Let say I have a field call NAME in a table.
When I do a select NAME from <table>. it shows

NAME
--------------
John, Smith
Jonathan, Williams
How do I do a select statment to make the display
look like this(without the comma, with 20 space in between, and
with the last name line up)?

NAME
---------------
John Smith
Jonathon Williams


Thanks

View 1 Replies View Related

Select Query

Jan 12, 2001

I have a SELECT query returning, say 200, rows. I want to grab middle 50 rows from this resultset.
Is their an easy way to write my SELECT statement which would help me retrieve only these 50 rows?

Thanks

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved