Showing posts with label provide. Show all posts
Showing posts with label provide. 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.

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, March 9, 2012

How to create a BAK of MSSQL database?

Hi,
WebAssist have asked us to provide them with a BAK of our MSSQL database.
Can anyone provide instruction on how to do that? We are using Enterprise
Manager and our database is hosted by our ISP on their server, which we have
access to.
Thanks
Nath.
Hi
BACKUP DATABASE mydb TO DISK ='C:\mydb.bak'
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:OMVgNucQGHA.5296@.TK2MSFTNGP09.phx.gbl...
> Hi,
> WebAssist have asked us to provide them with a BAK of our MSSQL database.
> Can anyone provide instruction on how to do that? We are using Enterprise
> Manager and our database is hosted by our ISP on their server, which we
> have access to.
> Thanks
> Nath.
>
|||Hi Uri,
Thank you very much.
Regards
nath.
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:%23BCJGDdQGHA.2300@.TK2MSFTNGP11.phx.gbl...
> Hi
> BACKUP DATABASE mydb TO DISK ='C:\mydb.bak'
>
>
> "Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
> news:OMVgNucQGHA.5296@.TK2MSFTNGP09.phx.gbl...
>
|||No file though?
SQL SERVER BACKUP
database name: ourdbname
name: our backup
description: <blank>
Backup - we have "database complete" selected
Destination - we have C:\ourdbase.bak
When we click "OK" it seems to run through everything successfully, except
there is no ourdbase.bak file on our C drive! Are we saving it to our ISP's
C drive considering that the MSSQL database is hosted there?
Hope you can help. Thanks again.
Regards
Nath.
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:%23P5JDGdQGHA.516@.TK2MSFTNGP15.phx.gbl...
> Hi Uri,
> Thank you very much.
> Regards
> nath.
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:%23BCJGDdQGHA.2300@.TK2MSFTNGP11.phx.gbl...
>
|||Yes path are always relative to the server you are working on.
HTH, Jens Suessmeyer.
|||Hi,
Is there any way to save the file locally? Our ISP (Fasthosts) don't seem
to understand what we are asking them and keep trying to force us to use DTS
to backup the database.
We've got Microsoft SQL Server 8.0 installed but, to be honest, we're just
using this to link to 2 databases hosted by our ISP.
How do we create a MSSQL database locally, so that we could import the data
in and THEN do the All Tasks > Database Backup?
Thanks
Nath.
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1141728051.055622.165600@.z34g2000cwc.googlegr oups.com...
> Yes path are always relative to the server you are working on.
> HTH, Jens Suessmeyer.
>
|||> Is there any way to save the file locally?
That would require that the account that the SQL Server service is running under at your ISP had
connection and permissions to a share on your machine. Not likely, and not something you want. This
is how windows work. How about backup locally at your ISP and then FTP the file? If your ISP don't
give you an option to backup and save the backup locally you should change ISP immediately...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:%23U4%23kodQGHA.5808@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Is there any way to save the file locally? Our ISP (Fasthosts) don't seem to understand what we
> are asking them and keep trying to force us to use DTS to backup the database.
> We've got Microsoft SQL Server 8.0 installed but, to be honest, we're just using this to link to 2
> databases hosted by our ISP.
> How do we create a MSSQL database locally, so that we could import the data in and THEN do the All
> Tasks > Database Backup?
> Thanks
> Nath.
> "Jens" <Jens@.sqlserver2005.de> wrote in message
> news:1141728051.055622.165600@.z34g2000cwc.googlegr oups.com...
>

How to create a BAK of MSSQL database?

Hi,
WebAssist have asked us to provide them with a BAK of our MSSQL database.
Can anyone provide instruction on how to do that? We are using Enterprise
Manager and our database is hosted by our ISP on their server, which we have
access to.
Thanks
Nath.Hi
BACKUP DATABASE mydb TO DISK ='C:\mydb.bak'
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:OMVgNucQGHA.5296@.TK2MSFTNGP09.phx.gbl...
> Hi,
> WebAssist have asked us to provide them with a BAK of our MSSQL database.
> Can anyone provide instruction on how to do that? We are using Enterprise
> Manager and our database is hosted by our ISP on their server, which we
> have access to.
> Thanks
> Nath.
>|||Hi Uri,
Thank you very much.
Regards
nath.
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:%23BCJGDdQGHA.2300@.TK2MSFTNGP11.phx.gbl...
> Hi
> BACKUP DATABASE mydb TO DISK ='C:\mydb.bak'
>
>
> "Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
> news:OMVgNucQGHA.5296@.TK2MSFTNGP09.phx.gbl...
>> Hi,
>> WebAssist have asked us to provide them with a BAK of our MSSQL database.
>> Can anyone provide instruction on how to do that? We are using
>> Enterprise Manager and our database is hosted by our ISP on their server,
>> which we have access to.
>> Thanks
>> Nath.
>|||No file though?
SQL SERVER BACKUP
database name: ourdbname
name: our backup
description: <blank>
Backup - we have "database complete" selected
Destination - we have C:\ourdbase.bak
When we click "OK" it seems to run through everything successfully, except
there is no ourdbase.bak file on our C drive! Are we saving it to our ISP's
C drive considering that the MSSQL database is hosted there?
Hope you can help. Thanks again.
Regards
Nath.
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:%23P5JDGdQGHA.516@.TK2MSFTNGP15.phx.gbl...
> Hi Uri,
> Thank you very much.
> Regards
> nath.
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:%23BCJGDdQGHA.2300@.TK2MSFTNGP11.phx.gbl...
>> Hi
>> BACKUP DATABASE mydb TO DISK ='C:\mydb.bak'
>>
>>
>> "Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
>> news:OMVgNucQGHA.5296@.TK2MSFTNGP09.phx.gbl...
>> Hi,
>> WebAssist have asked us to provide them with a BAK of our MSSQL
>> database.
>> Can anyone provide instruction on how to do that? We are using
>> Enterprise Manager and our database is hosted by our ISP on their
>> server, which we have access to.
>> Thanks
>> Nath.
>>
>|||Yes path are always relative to the server you are working on.
HTH, Jens Suessmeyer.|||Hi,
Is there any way to save the file locally? Our ISP (Fasthosts) don't seem
to understand what we are asking them and keep trying to force us to use DTS
to backup the database.
We've got Microsoft SQL Server 8.0 installed but, to be honest, we're just
using this to link to 2 databases hosted by our ISP.
How do we create a MSSQL database locally, so that we could import the data
in and THEN do the All Tasks > Database Backup?
Thanks
Nath.
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1141728051.055622.165600@.z34g2000cwc.googlegroups.com...
> Yes path are always relative to the server you are working on.
> HTH, Jens Suessmeyer.
>|||> Is there any way to save the file locally?
That would require that the account that the SQL Server service is running under at your ISP had
connection and permissions to a share on your machine. Not likely, and not something you want. This
is how windows work. How about backup locally at your ISP and then FTP the file? If your ISP don't
give you an option to backup and save the backup locally you should change ISP immediately...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:%23U4%23kodQGHA.5808@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Is there any way to save the file locally? Our ISP (Fasthosts) don't seem to understand what we
> are asking them and keep trying to force us to use DTS to backup the database.
> We've got Microsoft SQL Server 8.0 installed but, to be honest, we're just using this to link to 2
> databases hosted by our ISP.
> How do we create a MSSQL database locally, so that we could import the data in and THEN do the All
> Tasks > Database Backup?
> Thanks
> Nath.
> "Jens" <Jens@.sqlserver2005.de> wrote in message
> news:1141728051.055622.165600@.z34g2000cwc.googlegroups.com...
>> Yes path are always relative to the server you are working on.
>> HTH, Jens Suessmeyer.
>

How to create a BAK of MSSQL database?

Hi,
WebAssist have asked us to provide them with a BAK of our MSSQL database.
Can anyone provide instruction on how to do that? We are using Enterprise
Manager and our database is hosted by our ISP on their server, which we have
access to.
Thanks
Nath.Hi
BACKUP DATABASE mydb TO DISK ='C:\mydb.bak'
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:OMVgNucQGHA.5296@.TK2MSFTNGP09.phx.gbl...
> Hi,
> WebAssist have asked us to provide them with a BAK of our MSSQL database.
> Can anyone provide instruction on how to do that? We are using Enterprise
> Manager and our database is hosted by our ISP on their server, which we
> have access to.
> Thanks
> Nath.
>|||Hi Uri,
Thank you very much.
Regards
nath.
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:%23BCJGDdQGHA.2300@.TK2MSFTNGP11.phx.gbl...
> Hi
> BACKUP DATABASE mydb TO DISK ='C:\mydb.bak'
>
>
> "Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
> news:OMVgNucQGHA.5296@.TK2MSFTNGP09.phx.gbl...
>|||No file though?
SQL SERVER BACKUP
database name: ourdbname
name: our backup
description: <blank>
Backup - we have "database complete" selected
Destination - we have C:\ourdbase.bak
When we click "OK" it seems to run through everything successfully, except
there is no ourdbase.bak file on our C drive! Are we saving it to our ISP's
C drive considering that the MSSQL database is hosted there?
Hope you can help. Thanks again.
Regards
Nath.
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:%23P5JDGdQGHA.516@.TK2MSFTNGP15.phx.gbl...
> Hi Uri,
> Thank you very much.
> Regards
> nath.
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:%23BCJGDdQGHA.2300@.TK2MSFTNGP11.phx.gbl...
>|||Yes path are always relative to the server you are working on.
HTH, Jens Suessmeyer.|||Hi,
Is there any way to save the file locally? Our ISP (Fasthosts) don't seem
to understand what we are asking them and keep trying to force us to use DTS
to backup the database.
We've got Microsoft SQL Server 8.0 installed but, to be honest, we're just
using this to link to 2 databases hosted by our ISP.
How do we create a MSSQL database locally, so that we could import the data
in and THEN do the All Tasks > Database Backup?
Thanks
Nath.
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1141728051.055622.165600@.z34g2000cwc.googlegroups.com...
> Yes path are always relative to the server you are working on.
> HTH, Jens Suessmeyer.
>|||> Is there any way to save the file locally?
That would require that the account that the SQL Server service is running u
nder at your ISP had
connection and permissions to a share on your machine. Not likely, and not s
omething you want. This
is how windows work. How about backup locally at your ISP and then FTP the f
ile? If your ISP don't
give you an option to backup and save the backup locally you should change I
SP immediately...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:%23U4%23kodQGHA.5808@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Is there any way to save the file locally? Our ISP (Fasthosts) don't seem
to understand what we
> are asking them and keep trying to force us to use DTS to backup the datab
ase.
> We've got Microsoft SQL Server 8.0 installed but, to be honest, we're just
using this to link to 2
> databases hosted by our ISP.
> How do we create a MSSQL database locally, so that we could import the dat
a in and THEN do the All
> Tasks > Database Backup?
> Thanks
> Nath.
> "Jens" <Jens@.sqlserver2005.de> wrote in message
> news:1141728051.055622.165600@.z34g2000cwc.googlegroups.com...
>