I Thought I Posted This One But Don't See It. Problem With Querying A Query

Jul 20, 2005

It is my understanding that Views cannot have parameters. Also that
stored procedures can not be queried. My problem is this:

I want to select the rows that match a certain parameter.

From that I want to select the most current 20 rows (there is a date
field).

From that I want to select the lowest 10 rows based on a numeric
field.

Finally I want that to be input to a report and some calculations.

What this basically is the selection for USGA Golf Handicap Index. It
is the most current 20 rounds of golf by a golfer, then the best 10 of
those 20 and then finally the calculation.

Any help would be appreciated.

View 3 Replies


ADVERTISEMENT

Noob Alert! What I Thought Was A Real Simple Query...

Oct 22, 2007

Hi

I have a table which has the column [itemNumber] Which contains numbers from 000 to 999. I have another table which has the UPC data for given items
I am trying to get results from my query that will show me every number in the itemNumberSet table that does not already exist (in the substring) of the UPCcode column.

By using the query below i am able to retrieve the opposite, and it works by returning results that do exist in the UPCcode column. But I cannot seem to get it to do the opposite which is what i am after. I figured it would be as simple as using NOT IN but that returned 0 results.


SELECT itemNumber FROM itemNumberSet
WHERE itemNumber IN (select SUBSTRING(UPCcode, 9, 3) FROM itemUPCtable)
ORDER BY itemNumber


Thanks for any suggestions you might have.
J

View 3 Replies View Related

Please Tell Me How To See My Posted Questions

Oct 18, 2006

hi, i have posted some threads before some weak, now i want to refer those threads,so please help me to get those threads, i forget threads names.

View 2 Replies View Related

Permission To View The Posted Reports

Apr 30, 2008

Hi,
This is regarding the SQL 2005 Report Manager (http://localhost/Reports) page. I have posted the reports, the reports run fine, buttons like new folder, new data source, etc... are visible (lets call this machine as A). The problem is when my machine is accessed from a nearby computer on the same network as http://machineA/Reports, the Report manager Home page appears with limited or no buttons. The reports are also not visible in the browser of machine B. How do I make the reports visible to users (grant permission) for them to run and view those reports?

In a nutshell, how the posted reports be accessed by users?

Thanks,
Raj

View 1 Replies View Related

Querying Result Set Of Another Query

Oct 3, 2007



Hi,

I have a query that returns the result set as follows

Querey
-----------------

select Code ,Date from

(

select *

from MasterTable

where ID= 1 OR ID = 3

)as data

unpivot

(

Date for Code in ( COD1,COD2,COD3 )

) as UPVT)

Result

CODE DATE
------------------------------------------------------------
COD1 2007-09-11 02:00:00.000
COD2 2007-09-21 02:00:00.000
COD1 2007-10-11 02:00:00.000
COD2 2007-09-12 02:00:00.000
COD3 2007-09-11 02:00:00.000




I just wanted to write the query using the result set of the above unpivot query and expecting the result as foolows

CODE DATE
------------------------------------------------------------
COD2 2007-09-21 02:00:00.000
COD1 2007-10-11 02:00:00.000
COD3 2007-09-11 02:00:00.000

The condition is that i wanted to have the code that has latest date.

Can any one please let me know the query??

~Mohan

View 3 Replies View Related

Not Returning What I Thought It Should

Nov 21, 2005

SELECT e.LastName + ',' + e.FirstName + ' - ' + e.EmployeeID AS ListBoxText, e.EmployeeID, e.LastName + ',' + e.FirstName AS FullNameFROM Employee e INNER JOIN EmployeeEval ev ON  ev.PeriodID = @Period WHERE (ev.Approved = 0) AND (e.DeptID = @deptID)GOI want to select everyone from the employee table in a dept (determined by DDL) who has either a) had a review and not been approved yet - or b) has not had a review yet  ---- all employees are in the employee table -- and all reviews are placed in the employeeeval table. 

View 4 Replies View Related

Well I Thought This Might Work...

Apr 8, 2008

So I've been working on this project and I've finally gotten into the program stages. However, I've realised some things that I need to change to some of my stored procedures so that they work the way I want them to inside the program. Anyways I have this stored procedure called "Delete_Minors" and what it originally did was delete any class found in this table called MinorRequiredClasses that matched that minor and was not considered complete. I realised that this would be a bad decision to delete classes in a minor and not consider any other majors/minors a user might have that also require those classes...SO I thought I might be able to come up with a query but it doesn't seem to work. Below are the tables the query/stored procedure deals with as well as the old procedure and the new one (that I attempted to work the way i wanted it to).





Code Snippet

DECLARE @studid int
DECLARE @minorid varchar(50)

SET @studid = 0
SET @minorid = 'Computer Science'

IF (SELECT COUNT(*) FROM Student_Minors sMinors WHERE sMinors.MinorID = @minorid AND sMinors.StudentID = @studid) > 0
BEGIN
DELETE FROM Student_Classes
WHERE StudentID = @studid AND Completed = 0
AND ClassID IN (SELECT minReqC.ClassID
FROM MinorRequiredClasses minReqC
WHERE minReqC.MinorID = @minorid)
AND ClassID NOT IN (SELECT majReqC.ClassID
FROM MajorRequiredClasses majReqC
WHERE majRecC.MajorDisciplineID IN (SELECT sMajors.MajorDisciplineID
FROM Student_Majors sMajors
WHERE sMajors.StudentID = @studid))

DELETE FROM Student_Minors
WHERE StudentID = @studid AND MinorID = @minorid
END

USE [C:COLLEGE ACADEMIC TRACKERCOLLEGE ACADEMIC TRACKERCOLLEGE.MDF]
GO
/****** Object: Table [dbo].[MinorRequiredClasses] Script Date: 04/07/2008 22:49:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MinorRequiredClasses](
[MinorClassID] [int] IDENTITY(0,1) NOT NULL,
[MinorID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ClassID] [varchar](7) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_MinorRequiredClasses] PRIMARY KEY CLUSTERED
(
[MinorClassID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[MinorRequiredClasses] WITH CHECK ADD CONSTRAINT [FK_MinorRequiredClasses_ClassID] FOREIGN KEY([ClassID])
REFERENCES [dbo].[Classes] ([ClassID])
GO
ALTER TABLE [dbo].[MinorRequiredClasses] CHECK CONSTRAINT [FK_MinorRequiredClasses_ClassID]
GO
ALTER TABLE [dbo].[MinorRequiredClasses] WITH CHECK ADD CONSTRAINT [FK_MinorRequiredClasses_MinorName] FOREIGN KEY([MinorID])
REFERENCES [dbo].[Minors] ([MinorID])
GO
ALTER TABLE [dbo].[MinorRequiredClasses] CHECK CONSTRAINT [FK_MinorRequiredClasses_MinorName]

USE [C:COLLEGE ACADEMIC TRACKERCOLLEGE ACADEMIC TRACKERCOLLEGE.MDF]
GO
/****** Object: Table [dbo].[MinorRequiredClasses] Script Date: 04/07/2008 22:49:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MinorRequiredClasses](
[MinorClassID] [int] IDENTITY(0,1) NOT NULL,
[MinorID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ClassID] [varchar](7) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_MinorRequiredClasses] PRIMARY KEY CLUSTERED
(
[MinorClassID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[MinorRequiredClasses] WITH CHECK ADD CONSTRAINT [FK_MinorRequiredClasses_ClassID] FOREIGN KEY([ClassID])
REFERENCES [dbo].[Classes] ([ClassID])
GO
ALTER TABLE [dbo].[MinorRequiredClasses] CHECK CONSTRAINT [FK_MinorRequiredClasses_ClassID]
GO
ALTER TABLE [dbo].[MinorRequiredClasses] WITH CHECK ADD CONSTRAINT [FK_MinorRequiredClasses_MinorName] FOREIGN KEY([MinorID])
REFERENCES [dbo].[Minors] ([MinorID])
GO
ALTER TABLE [dbo].[MinorRequiredClasses] CHECK CONSTRAINT [FK_MinorRequiredClasses_MinorName]

USE [C:COLLEGE ACADEMIC TRACKERCOLLEGE ACADEMIC TRACKERCOLLEGE.MDF]
GO
/****** Object: Table [dbo].[MajorRequiredClasses] Script Date: 04/07/2008 22:50:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MajorRequiredClasses](
[MajorClassID] [int] IDENTITY(0,1) NOT NULL,
[MajorDisciplineID] [int] NULL,
[ClassID] [varchar](7) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_MajorRequiredClasses] PRIMARY KEY CLUSTERED
(
[MajorClassID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[MajorRequiredClasses] WITH CHECK ADD CONSTRAINT [FK_MajorRequiredClasses_ClassID] FOREIGN KEY([ClassID])
REFERENCES [dbo].[Classes] ([ClassID])
GO
ALTER TABLE [dbo].[MajorRequiredClasses] CHECK CONSTRAINT [FK_MajorRequiredClasses_ClassID]
GO
ALTER TABLE [dbo].[MajorRequiredClasses] WITH CHECK ADD CONSTRAINT [FK_MajorRequiredClasses_MajorDisciplineID] FOREIGN KEY([MajorDisciplineID])
REFERENCES [dbo].[MajorDisciplines] ([MajorDisciplineID])
GO
ALTER TABLE [dbo].[MajorRequiredClasses] CHECK CONSTRAINT [FK_MajorRequiredClasses_MajorDisciplineID]

OLD QUERY
DECLARE @studid int
DECLARE @minorid varchar(50)

SET @studid = 0
SET @minorid = "Computer Science"
DELETE FROM Student_Classes
WHERE StudentID = @studid AND Completed = 0
AND ClassID IN (SELECT minReqC.ClassID
FROM MinorRequiredClasses minReqC
WHERE minReqC.MinorID = @minorid)

NEW QUERY
DECLARE @studid int
DECLARE @minorid varchar(50)

SET @studid = 0
SET @minorid = 'Computer Science'
DELETE FROM Student_Classes
WHERE StudentID = @studid AND Completed = 0
AND ClassID IN (SELECT minReqC.ClassID
FROM MinorRequiredClasses minReqC
WHERE minReqC.MinorID = @minorid)
AND ClassID NOT IN (SELECT majReqC.ClassID
FROM MajorRequiredClasses majReqC
WHERE majRecC.MajorDisciplineID IN (SELECT sMajors.MajorDisciplineID
FROM Student_Majors sMajors
WHERE sMajors.StudentID = @studid))
Let me know if you need more information...Hope someone can help!

View 4 Replies View Related

I Thought This Would Be Simple...

Jul 14, 2006

I had originally thought a full outer join would solve this, but alas I'm a roadblock. Perhaps it's because it's a Friday!

The goal is to create the most efficient query that will display results of the daily calls and sales as
this:

Date EmpID Calls Sales
7/1/2006 1 20 5
7/1/2006 2 25 7
7/1/2006 3 NULL 1
7/1/2006 4 10 NULL

The problem is a simple full outer join ends up ignoring EmpID 3 who has no Calls in t1, but I still want that row displayed in the results. Any ideas? TIA

create table t1 (Date smalldatetime, EmpID int, Calls int)

create table t2 (Date smalldatetime, EmpID int, Sales int)

insert into t1
values ('7/1/2006', 1, 20)

insert into t1
values ('7/1/2006', 2, 25)

insert into t1
values ('7/1/2006', 4, 10)

insert into t2
values ('7/1/2006', 1, 5)

insert into t2
values ('7/1/2006', 2, 7)

insert into t2
values ('7/1/2006', 3, 1)

View 5 Replies View Related

SQL Query Question- Querying The Middle Table In A M To M

May 17, 2000

I need help with a query, and I haven't seen anything like this in a SQL book.

I will use the Northwind database for this example. The tables I am using are Products, Order_Detail, and Orders. There is a many to many relationship between Products and Orders, that is resolved by the Order_Detail table. Suppose I want to find out which products are related to each order. How would I query the tables?

Thanks everyone,
Nathan

View 1 Replies View Related

This Is More Of An Access Question, But I Thought I'd Try..

Feb 3, 2004

I have a hunch this one is going to be a resounding "no", but I thought I'd try anyways.

I have a report that uses a user defined date range many, many times throughout the datasource. Ideally, I would like to pass a query declaring and setting variables and let sql server (2000) sort out the dirty work. Essentially I'm working on something that would look like this:

DECLARE @sDate AS DATETIME
DECLARE @eDate AS DATETIME

SET @sDate = 'this string gets constructed during the On Open event of a report
SET @eDate = 'same thing here

SELECT lotsOfStuff, (SELECT oneOfManySubSelects FROM t2 WHERE t2.field BETWEEN @sDate AND @eDate)
FROM somewhere
WHERE somefield BETWEEN @sDate AND @eDate

I have some five subselects that are dependent on this daterange. I can construct the entire string purely in VB, but it's messy and rather tedious. Ideally I'd like to set the variable ONCE at runtime and be done with it. This way, I keep a full record source that calls @sDate and @eDate. Then I simply set the variables and insert them before the query.

The problem is Access doesn't seem to know how to pass the query without trying to parse the variables itself. So it gets mad that @sDate and @eDate haven't been defined for each occurance. I'm looking for a way to make access ignore the fact that there are variables in the query, and pass it as-is to the sql server.

Thoughts?

View 3 Replies View Related

Apply Your Thought On Char To Int

Feb 7, 2004

HI FRIENDS,

IS THERE ANY PERFORMANCE IMPACT WHEN I USE "CHAR" AS A DATA TYPE INSTEAD OF USING "INT" FOR RETRIEVING DATA OR FOR SOME COMPLEX QUERY.

THANKS
WITH BEST REGARDS,
DHIRAJ

View 3 Replies View Related

Forward Looking Thought: Raw Files

Oct 6, 2006

I assume that MS has a directive never to change the format of SSIS raw files...

However, what I'd like to know is that when I'm planning long-term systems where I've got backups of data (staging, logging, whatever) using raw files, can I be assured that future versions of SSIS will be able to read those raw files?

I assume a certain level of backwards compatibility, however, I'm just curious if I should think about building processes into my projects that would factor that in and rebuild raw files everytime a new/major release of SSIS comes out.

Phil

View 5 Replies View Related

Okay, I Thought I Had The Return Value From A Statement Figured Out...

Nov 15, 2007

  So, Jimmy G helped me out with it in showing a little bit how to do it. SqlCommand command = new SqlCommand(, object>)
SqlParameter param = new SqlParameter();
param.ParameterName = "@return";
param.Direction = ParameterDirection.ReturnValue;
command.Parameters.Add(param);

command.ExecuteNonQuery();

//get the return value
int val = int.Parse(command.Parameters[0].ToString());  
 Where I get lost is in the declaring of a new sqlcommand and sqlparameter. Can you please spell out where to use this and if I need to change my SQLdataSource. I currently was trying to use it in the OnClick of a button. What I had did the following
 Protected Sub CreateIssue_Click(ByVal sender As Object, ByVal e As System.EventArgs)        dim returnValue as integer        'how do I get a return value from the stored procedure executed in 'insertissue.insert() here to a variable?             InsertIssue.Insert()        Response.Redirect("/addarticletoissue")            End Sub
 
again, thank you for your help and patience with such a beginner =)

View 2 Replies View Related

Food For Thought (ReIndex And Log Shipping)

Dec 29, 2003

I have a production 60GB database set to Full Recovery and every 15 minutes I am log shipping to a Stand by Server .

During the production hours there are no problems but at night when I run DBCC DBREINDEX, the log grows to 22GB and because of this I have a problem sending this over the network to the stand by server.

I tried changing the recovery model to Bulk_Logged but the there is no difference in log file backup size.

AnyIdea

View 1 Replies View Related

Simple OUTER JOIN (I Thought)

Sep 11, 2007

Two tables:FruitfruitID, fruitNameBasketbuyerID, fruitID(ie. we can see which buyer has what fruit in their basket)I simply want to display all available fruit and whether or not it'sin a specific persons' basket.SELECT Fruit.fruitID, Fruit.fruitName, IsNull(buyerID, 0)FROM Fruit INNER JOIN Basket ON Fruit.fruitID = Basket.fruitIDWHERE Basket.buyerID = 12but this just gives me what's in buyer 12s' basket.What am I doing wrong? Am I a basket case...

View 2 Replies View Related

SQL Select Statement To Select The Last Ten Records Posted

Aug 6, 2007

SELECT Top 10    Name, Contact AS DCC, DateAdded AS DateTimeFROM         NameTaORDER BY DateAdded DESC
I'm trying to right a sql statement for a gridview, I want to see the last ten records added to the to the database.  As you know each day someone could add one or two records, how can I write it show the last 10 records entered.

View 2 Replies View Related

Query A SQL Server Compact Table While Querying A SQL 2005 Server Table

May 21, 2008

Hi there,

I'm trying to run a query on a SQL Server 2005 table which has a WHERE clause that requires a query from my SQL Compact table.



SELECT * from RemoteDB.TESTDB.dbo.Objects

WHERE Last_Updated > '2008-05-21 10:51:00'

AND Object_PARENT IN (select Object_CODE from LocalDB.PDADB.dbo.Objects)


Basicallly on a linked system, this query would find all new objects in my main database where the same objects exist in my local database. This would work just perfectly, no problems.

Now, the local database is actually on a PDA running SQL Server Compact Edition. There is currently no support for creating a linked environment. I have the option of pulling the table off the local db and pushing it to the remote db and then running the above query from within the single db and then retrieving the list of new entries and pulling them down to the local db but that is a HUGE amount of bandwidth, even if I just used the single primary key column.

Would anyone maybe have a little advice for me on how I could possibly achieve the above result on SQL Server Compact please?


Thanks in advance

View 10 Replies View Related

Querying Help

Sep 9, 2007




I'm a newbie to SQL and wanted to see if someone could help me write a query. I store historical options data in a SQL data base and I'm trying to create a query that will retrieve all ATM (at the money options).

For each unique stock symbol (STOCK_SYMBOL) in my database find the strike price (STRIKE) which is closest to the stock price (UND_LAST). This will be refined by the EXPIRATION and OPT_TYPE

The following query returns all options not just ATM options.

SELECT STOCK_SYMBOL, UND_LAST, STRIKE, EXPIRATION FROM DATA

WHERE EXPIRATION > '2007-02-01 00:00:00'
AND EXPIRATION < '2007-02-28 00:00:00'
AND OPT_TYPE = 'CALL'


Related DB fields.

STOCK_SYMBOL
STRIKE
UND_LAST
OPT_TYPE

EXPIRATION

Any help would be appreciated.

View 2 Replies View Related

Querying SAP Through

Nov 8, 2007

I am using MS SQL Server 2005 Import and Export Wizard (.net framework Data Provider for mySAP Business Suite. )

as a interface between SAP and MS SQL 2005.

Once the connection is created i can use basic query to fetch the data from SAP tables
ie., SELECT * FROM AFPO

But say I want to EXTRACT data just for month of July from AFPO.

AFPO does not have date field so you have to join AFPO to AUFK and AUFK to COEP to fetch the date as a criteria to restrict data for the month of July .

This can be done in ABAP by view or Interim Table, if you have Developer Key.

Can anyone please tell me if aforesaid is possible with MS SQL Server 2005 Import and Export Wizard query ?


View 3 Replies View Related

Querying By A Date

Nov 9, 2006

Hello,
I want to find all the entries where the date field is a specific date; so I may have 5 entries with the date 1/1/2006, and I want to find all of those.  However, datetime fields in SQL Server also have the time, so how do you handle that?  Can you just say where requestdate = getdate() to get all of the entries that have records for today?
How does time affect this?

View 5 Replies View Related

Help With SQL Select Querying

Sep 28, 2007

 Hi,I am new to sql and was wondering if someone could help with this select statement. please don't laugh! SELECT * FROM  product_detailsWHERE MemberId = @MemberIdINNER JOIN  Member_Ratings ON  product_details.MemberId = member_ratings.MemberIdSELECT COUNT(*) FROM  member_ratings AS FinalHighRating WHERE member_ratings.MemberId =  product_details.MemberId AND member_ratings.Rating = 5  Any questions? Thanks! 

View 7 Replies View Related

Querying Like Datetime

Oct 31, 2007

Hey,
What is the best way to query two datetime values to see if they are alike?  I need to determine if an [AccountEndDate] is today (both values are datetime).  Using "Like" does not work.
Thanks!

View 4 Replies View Related

Querying SQL Views

Jan 27, 2008

 If you create a view such as   CREATE VIEW TestView AS Select * FROM customers_table WHERE CustomerID between 213 AND 3443  Each time you want to select from the view - is the View going to perform the WHERE clause on the customers_table, or not? Or does the view already have the virtual rows?, meaning it does not have to perform a where clause  (WHERE CustomerID between 213 AND 3443) on the customers_table, and just performs an inner join with the rows it already has?  

View 5 Replies View Related

Querying Count

Aug 10, 2005

I have a usage table Aaccessdate (datetime)useridpageidI need to write a sql that would do a report on a monthly basis.  ( how many pagehits per month)All is fine - and my SQL looks likes thisselect count(pageid)from A.The twist here is , I do not want to count those records if the same user visits the page on the same day.For Eg02/03/2005 10:09:09.000 user1 page102/03/2005 15:09:09.000 user1 page102/03/2005 11:09:09.000 user2 page202/03/2005 16:09:09.000 user3 page3I want my count to give me back 3 instead of 4.Can this be done?ThanksRajini

View 4 Replies View Related

Querying A Datatable

Mar 20, 2006

I have a table containing prices. This table will be queried very often to provide quotes for clients.So to ease the burden on the server I want to cache the table and then just query the cached version.However it seems that I can only cache the table as a datatable. This means I have to query the datatable to get the prices for each quote.I'm not sure how to query a datatable. Is ther syntax similar to querying a SQL table?In fact is this best way to go about things?Any help would be appreciated.G

View 4 Replies View Related

Querying A View

Apr 20, 2006

Hi guys

im struggling to see what im doing wrong with the following SQL, wondering if it has something to do with the subquery being a view...cant think why though


select value from table
where type = 'Extra Mailbox'
and active = 1
and value not in
(select login from view)
order value

The view returns a list of logins and the type field is also a list of logins. I want to filter the list of logins that do not appear in the subquery....

Any ideas?

Thanks in advance for any responses.

Ging

View 2 Replies View Related

Need Advice/Help On Querying A Different Db

Oct 1, 2004

I have 2 different database's on the same server. I'm trying to create a stored proc that resides in Reporting database but queries against the Call database. 4 part naming convention gives me an error of 'invalid object name' What am I forgetting here?

View 5 Replies View Related

Querying Using Another Table

Apr 30, 2008

Hello all,

I have a table (tbl_a) with 2 columns: itemNames | Date .
ItemNames can have duplicates.
I have another table (tbl_b) with date ranges in 2 columns: startDate | endDate.

what I would like to do is: query tbl_a where date between startDate and endDate of tbl_b.

does anyone have an idea?
thanks in advance.

View 2 Replies View Related

Querying Two Tables

May 23, 2008

This is my problem

Table A Columns:

OriginatingNumber,
TerminatingNumber

Both of these columns contain npanxx numbers which would be the first 6 digits of a phone number, example 217345 which is in illinois.

Table B Columns:

npanxx,
state

table B hold all npanxx numbers in the united states and what state it pertains to.

what i need to do is run a query to check and see what state the OriginatingNumber and the TerminatingNumber are in and decide if both numbers passed are in the same state or not.

so for example in Table A Row 1: OriginatingNumber is 217345 and the TerminatingNumber is 309454. I need to check both of these numbers against table B and it would return that both numbers are in IL. Basically I need to return a result of yes or no. yes they are in the same state or no they are not in the same state.

Any help would be great

Thanks for reading,

Nick

View 3 Replies View Related

Querying The Database

Jun 12, 2008

how to write a query to find the no of tables present in that database.

Any suggestions.

View 4 Replies View Related

Querying Table More Than Once

Jun 12, 2008

Hi All

Thx in advanced for any help anyone can offer me.

I have 2 tables Staff and Class which are as follows

Staff
ID (Primary Key)
FirstName
MiddleName
Surname
Etc. . .

Class
ID (Primary key)
LessonTemplateID
TeacherID
TermID
AssistantID

LessonTemplateID and TermID link to other tables which i don't need right now.

The Class.TeacherID and Class.AssistantID both link to the Staff.ID

I am trying to create a query where i can say i want to select a class.ID of lets say 12 and display both the Teachers name and the Assistants Name.

If i do just one join between Staff.ID and lets say Class.TeacherID all is fine and i can display the teacher.FirstName for a particular class.ID. However my problem is when im trying to display both teacher and assistant. Every time i try to create a query to do this the query comes back blank.

Im really stuck on this and just can't figure it out (is it even possible?).

Thx for any help Scott.

View 2 Replies View Related

Querying Constraints In A DB

Jan 23, 2007

Hi there,

Is there a way where I can run a query or a store procedure where i can retrieve all the contraints attached to the tables in the database?

thanks

View 1 Replies View Related

Querying Other Databases

Apr 21, 2007

Hi All,
I am very new to sql and I am not really sure of what I am doing.

I have a bit of a complicated stored procedure that I am trying out. There is 3 parts to it to search for new articles,updates and discontinued articles for a particular Supplier. Right now I am just trying to get the first part working - I am trying to query another database that has 4 tables, 2 are joined ActiveArticle & ActiveArticlePrice and the other 2 are also joined UpdateArticle & UpdateArticlePrice. But all tables also hold data for ALL Suppliers, they are recognised by a GUID - SupplierGuid.

I want to compare them to each other to see if there are any new articles added to the Update tables. This is what I have so far, I was hoping someone could tell me if they see some obvious mistakes(I'm sure theres many!). For the first select, I tried adding a couple of parameters Flag and Text to use so that I can order it all once i have the 3 parts working. But I don't know the syntax is right, because then I also want to select all fields in both tables?.

CREATE PROCEDURE Portal_GetPriceListUpdates
(

@SupplierGUID uniqueidentifier
)
AS

SELECT 'A' AS FLAG, 'New Product' AS TEXT, * FROM SupplierUnits.UpdateArticle UA, SupplierUnits.UpdateArticlePrice UAP WHERE EXISTS
(SELECT * FROM UA, UAP WHERE UA.SupplierGuid=@SupplierGUID AND UA.SupplierArticleNumber NOT IN (SELECT SupplierArticleNumber FROM SupplierUnits.ActiveArticle.SupplierArticleNumber))

GO

I would appreciate any help!
Thanks,
pp

View 2 Replies View Related







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