Solved

How To Create This Stored Procedure?

Posted on 2009-04-02
1
173 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:
udaya kumar laligondla 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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

860 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