[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Use SQL Statment in Store procedure as a table

Posted on 2013-01-10
1
Medium Priority
?
304 Views
Last Modified: 2013-01-10
Hi Experts,

I have the below mentioned SQL statment, which I need to use in a store procedure as a table On the top to refer any where under the same SP. Please help


SELECT     TOP (100) PERCENT a.dt, a.dn, a.isholiday, a.holiday_name, b.EmpCode, b.EmpName,
                      CASE WHEN b.Direct = '1' THEN '1' ELSE '0' END AS Direct
FROM         dbo.AllDates a CROSS JOIN
             dbo.Emp_Info b
WHERE    b.CC=@CC and (b.Branch = 'KHI') and a.dt between @Dt and @Dt
and @Dt Between coalesce(JoiningDate,@Dt) and coalesce(RegsinedOn,@Dt)
ORDER BY a.dt, b.EmpCode
0
Comment
Question by:Mehram
[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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38762473
as it has parameters, you cannot refer to it as a table Unless you store the results in a table.
it may be a table variable:

declare @t table ( dt datetime, dn varchar(10) ... etc .. )
insert into @t select top (100) percent ... etc

and from there you can then use the @t table:

select * from @t

etc ..
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 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