Showing posts with label views. Show all posts
Showing posts with label views. Show all posts

Wednesday, March 28, 2012

how to create parameterised views?

I am using SqlServer2005 and asp.net 2005. I have a large database for which I have to provide reports for it. I need a report that user will specify a date, and the report will be run, from this month & year and I will calculate the first day of the month and the last day of the month and these will serve as the input parameters for a long SELECT query.

For my previous reports i've used views . But for this functionality i need a parameterized view, which i cant create.

Please help me how to create a parameterized view...

Thanks in Advance...

Use a stored procedure.

|||

Given a date and if you need to find the first day of the month/last day of the month here's how you can do it.

DECLARE @.DdatetimeSET @.D =getdate()SELECT ,DATEADD(dd, -DATEPART(dd,GETDATE()) + 1,GETDATE())'First day of the month' ,DATEADD(d, -DAY(DATEADD(m,1,@.Date)),DATEADD(m,1,@.Date))AS'Last day of the month'

You can use the same in a view as follows:

SELECTFROM dbo.vwSomeViewWHERE DatecolumnBETWEEN @.begDateAND @.EndDate
|||

You can't create a parameterized view. You can create a view and then filter it. Or you can create a table valued function, which is pretty close to a parameterized view.

Monday, March 26, 2012

How to create indexes for views

Hi all,
It may be a stupid question but I'd be very happy if anyone could tell
my how to create an index on a view (creating an index on a table
works fine and is easy to do).
I have installed MS SQL Server 2000 running on a Windows 2000 machine.
Thanks in advance,
EdPlease read the page titled "Creating an Indexed View" for more information
on creating indexes on views. There are certain requirements to be met.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
What hardware is your SQL Server running on?
http://vyaskn.tripod.com/poll.htm
"Eddie" <e.beyer@.gmx.net> wrote in message
news:29d450bb.0310020627.489ee1ae@.posting.google.com...
Hi all,
It may be a stupid question but I'd be very happy if anyone could tell
my how to create an index on a view (creating an index on a table
works fine and is easy to do).
I have installed MS SQL Server 2000 running on a Windows 2000 machine.
Thanks in advance,
Ed|||I'd start by typing 'indexed views' into the keywords to find section of the
index in Books Online. You'll find a lot of information that will help you
get started and things you need to be aware of. Let us know if you have any
specific questions after reading some of the basics... I hope this helps!
--
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"Eddie" <e.beyer@.gmx.net> wrote in message
news:29d450bb.0310020627.489ee1ae@.posting.google.com...
> Hi all,
> It may be a stupid question but I'd be very happy if anyone could tell
> my how to create an index on a view (creating an index on a table
> works fine and is easy to do).
> I have installed MS SQL Server 2000 running on a Windows 2000 machine.
>
> Thanks in advance,
> Ed|||Hi Ed
Indexed views work best when the underlying data is
infrequently updated. The maintenance of an indexed view
can be higher than the cost of maintaining a table index.
If the underlying data is updated frequently, then the
cost of maintaining the indexed view data may outweigh the
performance benefits of using the indexed view.
There is a lot more info. in Books Online that I would
consider reading.
>--Original Message--
>Hi all,
>It may be a stupid question but I'd be very happy if
anyone could tell
>my how to create an index on a view (creating an index on
a table
>works fine and is easy to do).
>I have installed MS SQL Server 2000 running on a Windows
2000 machine.
>
>Thanks in advance,
>Ed
>.
>

Wednesday, March 21, 2012

How to create a View from temporary table ?

Hi all,
Iam aware that #Temporary tables can not be used in creation of views, but
iam in a situation where in iam needed to do so.
can anybody provide me with a workaround for this, its very urgent....any
help would be highly appreciated.
Thanks in advance,
Kishore> Iam aware that #Temporary tables can not be used in creation of views, but
> iam in a situation where in iam needed to do so.
Can you elaborate? Why do you need a temporary table and a permanent view
of that temporary table? This sounds like buying a house in Florida because
you're going there for spring break.|||Well, you can't do that.
So if that view that you want is something you will be using in all queries,
then select the required rows and insert into another temporary table and
use this assuming you are using a view.|||"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uWPH%23AedGHA.3632@.TK2MSFTNGP05.phx.gbl...
> This sounds like buying a house in Florida because
> you're going there for spring break.
Aaron,
One of these days I am going to put together a compilation of these
analogies of yours. You have a particular knack for them.
I'm not being sarcastic at all. You always manage to come up with a
comparison that suits the situation perfectly.|||Hi,
Thanks for your prompt reply.
As asked by you, i will try to elaborate a bit more, please pardon me for
this lengthy explanation as i am in very urgent need of it, any help would b
e
highly appreciated.
My Business need requires that i need to create a table whose columns names
are taken from data contained in different tables, in essence iam creating a
table dynamically, which will have different number of columns in each run.
For efficeincey purposes, my customers earlier implementation uses Temporary
tables.
finally that dynamic #Temptable is filled up with data and a select
statement applied on it returns the needed data in XML format.
Then they came across the SQL Server row size limit of some 8060 bytes,
since each of the column in my dynamic table is of type NVARCHAR(255), at
maximum i can add 15 columns only to it. so instead of having only single
table, i decided to host those columns in multiple tables, i mean 1-15
columns will be added to #temptable-1 then 16-30 columns will be added to
#temptable-2 and so on....
so that problem has been addressed, but the output of the final select
statement that works on the dynamic #Temptable is creating problem...earlie
r
there was only one table, but now there can be 'n' number of tables dependin
g
on the number of columns to be added, so the XML resulting from the select
statement on these 'n' number of dynamic #Temptables is different from the
earlier on when there was only one dynamic #Temptable, but i need to maintai
n
that format due to some other dependencies.
so i thought of creating a single view(since a table can not hold all the
columns resulting from the select statement on those 'n' number of tables)
from all those #Temptables and then generate XML from that single
view...which will be similar in syntax to the earlier case when there was
only a single #Temptable.
Hope this explains...
Thanks & Regards,
Kishore
"Aaron Bertrand [SQL Server MVP]" wrote:

> Can you elaborate? Why do you need a temporary table and a permanent view
> of that temporary table? This sounds like buying a house in Florida becau
se
> you're going there for spring break.
>
>|||becuase of the SQL Server 2000 row size limit of 8060 bytes i can put all my
columns taked from other #Temptables into a new #Temptable to be used as a
view as suggested by you, Total size of all my columns exceeds tht limit so
table option is ruled out.
"Omnibuzz" wrote:

> Well, you can't do that.
> So if that view that you want is something you will be using in all querie
s,
> then select the required rows and insert into another temporary table and
> use this assuming you are using a view.|||Mr Aaron,
have you seen my explanation, can you suggest me anything.
-Kishore
"Aaron Bertrand [SQL Server MVP]" wrote:

> Can you elaborate? Why do you need a temporary table and a permanent view
> of that temporary table? This sounds like buying a house in Florida becau
se
> you're going there for spring break.
>
>sql

Friday, February 24, 2012

How to copy views between servers?

I want to copy some views (not data) from one server to another.
How can I do that?
Sorry! I am using Sqlserver 2005
"ad" <flying@.wfes.tcc.edu.tw> glsD:ePT0y4ZhIHA.3940@.TK2MSFTNGP05.phx.g bl...
>I want to copy some views (not data) from one server to another.
> How can I do that?
>
|||Hi
Probably the easiest way is to script them and run the scripts. If you are
using version control you could just run the scripts you have already
(assuming they are autonomous).
Alternatively you can use SSIS and a "transfer object" task or SMO.
John
"ad" wrote:

> Sorry! I am using Sqlserver 2005
> "ad" <flying@.wfes.tcc.edu.tw> ???g?ó?l¥ó·s?D:ePT0y4ZhIHA.3940@.TK2MSFTN GP05.phx.gbl...
>
>
|||What is SSIS?
How can I do that?
"John Bell" <jbellnewsposts@.hotmail.com> glsD:8C605E23-915D-4E44-9626-1E720FA3BE2F@.microsoft.com...[vbcol=seagreen]
> Hi
> Probably the easiest way is to script them and run the scripts. If you are
> using version control you could just run the scripts you have already
> (assuming they are autonomous).
> Alternatively you can use SSIS and a "transfer object" task or SMO.
> John
> "ad" wrote:
|||Hi
SSIS is SQL Server Integration Services, it is only available on the
Standard and Enterprise Editions and you use SQL Server Business Intelligence
Development Studio (BIDS) to write the packages. You have not said which
version of SQL Server you are using! If you are on Express or Workgroup you
would need to script the procedures or use SMO. If you don't have Books
Online it can be downloaded from
http://www.microsoft.com/downloads/details.aspx?FamilyId=BE6A2C5D-00DF-4220-B133-29C1E0B6585F&displaylang=en
This has sections on SMO (just look it up in the index!)
John
"ad" wrote:

> What is SSIS?
> How can I do that?
> "John Bell" <jbellnewsposts@.hotmail.com> ???g?ó?l¥ó·s?D:8C605E23-915D-4E44-9626-1E720FA3BE2F@.microsoft.com...
>
>

How to copy views between servers?

I want to copy some views (not data) from one server to another.
How can I do that?Sorry! I am using Sqlserver 2005
"ad" <flying@.wfes.tcc.edu.tw> ¼¶¼g©ó¶l¥ó·s»D:ePT0y4ZhIHA.3940@.TK2MSFTNGP05.phx.gbl...
>I want to copy some views (not data) from one server to another.
> How can I do that?
>|||Hi
Probably the easiest way is to script them and run the scripts. If you are
using version control you could just run the scripts you have already
(assuming they are autonomous).
Alternatively you can use SSIS and a "transfer object" task or SMO.
John
"ad" wrote:
> Sorry! I am using Sqlserver 2005
> "ad" <flying@.wfes.tcc.edu.tw> ¼¶¼g©ó¶l¥ó·s»D:ePT0y4ZhIHA.3940@.TK2MSFTNGP05.phx.gbl...
> >I want to copy some views (not data) from one server to another.
> > How can I do that?
> >
>
>|||What is SSIS?
How can I do that?
"John Bell" <jbellnewsposts@.hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:8C605E23-915D-4E44-9626-1E720FA3BE2F@.microsoft.com...
> Hi
> Probably the easiest way is to script them and run the scripts. If you are
> using version control you could just run the scripts you have already
> (assuming they are autonomous).
> Alternatively you can use SSIS and a "transfer object" task or SMO.
> John
> "ad" wrote:
>> Sorry! I am using Sqlserver 2005
>> "ad" <flying@.wfes.tcc.edu.tw> ?gco?l¢Do¡Ps?D:ePT0y4ZhIHA.3940@.TK2MSFTNGP05.phx.gbl...
>> >I want to copy some views (not data) from one server to another.
>> > How can I do that?
>> >
>>|||Hi
SSIS is SQL Server Integration Services, it is only available on the
Standard and Enterprise Editions and you use SQL Server Business Intelligence
Development Studio (BIDS) to write the packages. You have not said which
version of SQL Server you are using! If you are on Express or Workgroup you
would need to script the procedures or use SMO. If you don't have Books
Online it can be downloaded from
http://www.microsoft.com/downloads/details.aspx?FamilyId=BE6A2C5D-00DF-4220-B133-29C1E0B6585F&displaylang=en
This has sections on SMO (just look it up in the index!)
John
"ad" wrote:
> What is SSIS?
> How can I do that?
> "John Bell" <jbellnewsposts@.hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:8C605E23-915D-4E44-9626-1E720FA3BE2F@.microsoft.com...
> > Hi
> >
> > Probably the easiest way is to script them and run the scripts. If you are
> > using version control you could just run the scripts you have already
> > (assuming they are autonomous).
> >
> > Alternatively you can use SSIS and a "transfer object" task or SMO.
> >
> > John
> >
> > "ad" wrote:
> >
> >> Sorry! I am using Sqlserver 2005
> >>
> >> "ad" <flying@.wfes.tcc.edu.tw> ?gco?l¢Do¡Ps?D:ePT0y4ZhIHA.3940@.TK2MSFTNGP05.phx.gbl...
> >>
> >> >I want to copy some views (not data) from one server to another.
> >> > How can I do that?
> >> >
> >>
> >>
> >>
>
>