Solved

How To Create This Stored Procedure?

Posted on 2009-04-02
1
168 Views
Last Modified: 2012-05-06
Hey everyone,

I'm trying to write a stored procedure that will return data from 2 tables (1 column in each table) based upon certain criteria.  The information I want is basically as follows:
UserName from dbo.Users (Column Users)
FileName from dbo.Files (column (FileName)

But I only want it where another column in dbo.Users (column Status) is equal to 7.  So far I have tried the SP listed below, but it's not returning any data:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



ALTER PROCEDURE [dbo].[sGetUserInfo]
AS
SELECT dbo.Users.UserName AS UserName, dbo.FileName.FileName
FROM dbo.Users INNER JOIN
                  dbo.Users ON dbo.Users.UserName = dbo.FileName.FilePrintStatus
WHERE (dbo.Users.Status = 7)
0
Comment
Question by:angus_young_acdc
1 Comment
 
LVL 12

Accepted Solution

by:
udayakumarlm earned 500 total points
ID: 24047918
try this. in join you are using user table twice
SELECT
dbo.Users.UserName AS UserName,
dbo.FileName.FileName
FROM dbo.Users
INNER JOIN
dbo.FileName ON dbo.Users.UserName = dbo.FileName.FilePrintStatus
WHERE (dbo.Users.Status = 7)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now