?
Solved

How To Create This Stored Procedure?

Posted on 2009-04-02
1
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 12

Accepted Solution

by:
udaya kumar laligondla earned 2000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

764 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