Solved

How To Create This Stored Procedure?

Posted on 2009-04-02
1
171 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

832 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