Solved

Use SQL Statment in Store procedure as a table

Posted on 2013-01-10
1
295 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Question 1 28
Adventure works database .msi 4 50
SQl works but add Having  by null or value 11 42
Having clause with Case 2 30
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…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

20 Experts available now in Live!

Get 1:1 Help Now