Solved

Use SQL Statment in Store procedure as a table

Posted on 2013-01-10
1
296 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
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting the 3 middle digits 4 36
Bubble user-defined Sql RAISERROR(...) to c# exception 14 147
How to place a condition in a filter criteria in t-sql (#2)? 10 43
Caste datetime 2 52
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discuā€¦
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based developeā€¦
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

25 Experts available now in Live!

Get 1:1 Help Now