Solved

How To Create This Stored Procedure?

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

708 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

12 Experts available now in Live!

Get 1:1 Help Now