Can You Use A VARIABLE In Place Of A Database Name?

Apr 8, 1999

Does anyone know if it is possible to use a variable in place of a database..table combination in a select statement

For Example: Instead of using the following with each database hardcoded in the SP:

select @dataused = sum(b.reserved)
from DBSglep..sysindexes b
where b.indid in (0, 1, 255) and segment != 2

I would like to loop for every database listed in sysdatabases and do this:

select @dbname = @dataname+'..sysindexes'

select @dataused = sum(b.reserved
from @dbname b
where b.indid in (0, 1, 255) and segment != 2

I have got the loop working, but just can't get the name substitution working as MSSQL dosn't seem to allow a variable after the FROM statement (it only seems to work with a hardcoded specific database..table name).

Any assistance in resolving this problem would be greatly appreciated! :-)

Many thanks in advance...

Regards,
Wayne

View 2 Replies


ADVERTISEMENT

How Do You Place A Variable In Your Gridview Sql Statement?

Apr 12, 2006

I have the below select command in my gridview that uses a library name.table approach in the sql. I created a label on the page and want to pass the label in where i have the libarary1 text in the select statement. This will allow me to swap out the production library with my development library when im working on the site (thru the use of a site variable) 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:as400con %>"ProviderName="<%$ ConnectionStrings:as400con.ProviderName %>" SelectCommand="SELECT * from  library1.table WHERE COMPANY = ? and ack = ? and HORZN_DATE <= ?">
<selectparameters><asp:controlparameter name="company" controlid="accts" propertyname="SelectedValue"/><asp:controlparameter name="ack" controlid="podropdown" propertyname="SelectedValue"/><asp:controlparameter name="dt" controlid="htoday" propertyname="Text"/></selectparameters>
How would I insert a label.text value into the select statement replacing the library1 ? I tried to use the asp:controlparameter adding the text and placing a ? mark in place of the library1 but it failed.
Thanks for any help you can lend on this,
Todd
 
 

View 5 Replies View Related

Is There A Place Where I Can Find The Events That Takes Place In Sql Server?

Jul 20, 2007

Is there a place where i can find events that takes place in the sql server? Like adding data to a database or something like that....



Regards

Karen

View 4 Replies View Related

Database Backup To Different Place

Mar 11, 2004

Hi All!

I know that if is want to backup my db on the c: drive i do this
BACKUP DATABASE DBName
TO DISK = 'c:isl_fs1DBName.bak'

BUT HOW do I take this to the network. I tried
BACKUP DATABASE DBName
TO DISK = '\isl_fs1DBName.bak'
it doesn't work please help

View 2 Replies View Related

Backup Database At Different Place

Mar 11, 2004

Hi All!

I know that if is want to backup my db on the c: drive i do this
BACKUP DATABASE DBName
TO DISK = 'c:isl_fs1DBName.bak'

BUT HOW do I take this to the network. I tried
BACKUP DATABASE DBName
TO DISK = '\isl_fs1DBName.bak'
it doesn't work please help

View 2 Replies View Related

Database Saving Place

Nov 11, 2006

Hello,

My english is not the best, but i will try my best.

I want to change the saving folder for the database from my systempartition to my datapartition (from c:labla to d:mydata), but i dont know how. I can see the folder but it is in gray font and unchangeable.

Greetings Thomas

View 1 Replies View Related

Create Copy Of Database And Place On Different Server

Oct 26, 2004

All,
I am trying to create a copy of an existing database and place on a different sql server for testing purposes. Currently my method of doing this is to create a backup, then restore a database on my new sql server. But here is the problem I am running into. When I look in Enterprise manager I can see all of the stored procedures and tables and data just fine, which is how I would like it. But, when I open up Query Analyzer I am not able to run any queries because it says "invalid object name" error. I know that the object name is correct. I think that I am having a conflict between the users which were carried over from the source backup file and the users that are on my 2 new sql server. If anyone could help, I would really appreciate it. I am stuck at this point. I am guessing it is probably something simple I am just unaware that I need to do.

Thanks,
LinsLo

View 3 Replies View Related

How Do I Quickly Populate A New Database With Place-holder Content?

Apr 28, 2008

I am using SQL server to create a rather complicated client database for a nonprofit organization. I have access to an ancient version of the database in Access format, but would rather create a new database from scratch instead of "up-sizing" the old database. Although the old database is mostly useless, it contains a goldmine of names and addresses that I could use to populate the new database that I'm creating. My question is this: Is there any relatively easy way to cut and paste from external data sources into a new SQL database? For example, I would love to just select twenty rows of "first names" from the old database and then paste that into my new table. Can anyone suggest any quick and easy tricks for populating a new database with place-holder content? Thanks! 

View 2 Replies View Related

Is There Any Method To Back Up The Database To Place Outside Of The Local Server System?

May 17, 2007

Hi, all experts here,

Thank you very much for your kind attention.

I am wondering if we could back up the databases to any place outside of the local server system? As I found, we can only back up the database to the local server system, so we have needs to share databases on network places. Is there any method to back up the database on network place rather than first of all I have to back up the database on a local server system, then copy it to the network place, that just sounds really inconvenient.

Thanks a lot in advance for your help and I am looking forward to hearing from you shortly.

With best regards,

Yours sincerely,



View 5 Replies View Related

Creating Database From Stored Proc With Variable Holding The Database Name

Aug 16, 2007

Here is my code


ALTER PROCEDURE Test
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @From varchar(10)
DECLARE @To varchar(10)
DECLARE @DBName varchar

SELECT TOP 1 @From = CONVERT(char,CreateDate,101) FROM CustomerInfo
WHERE TicketNum =
(SELECT TOP 1 TicketNum FROM CustomerInfo
WHERE CreateDate <= DATEADD(mm, -30, CURRENT_TIMESTAMP)
ORDER BY CreateDate DESC)
SELECT @To = CONVERT(char,GETDATE(),101)

SET @DBName = 'Archive_SafeHelp'
CREATE DATABASE @DBName + ' ' + @From + ' ' + @To
END


I am trying to create a database based on the name contained in the variables. I get the error 'Incorrect syntax near '@DBName'. How do i accomplish this?

Thanks
Ganesh

View 2 Replies View Related

How To Do Insert In Another Database When The Database Name Is A Variable

Mar 19, 2008

Hi,

We have different databases on the same server: Whrs001, Whrs002, etc. All databases have the same structure.

Suppose i have a table "location"
create table location
( location_id int not null primary key,
location_name varchar(50) not null )

I need to inserts data in "location" tables of different databases. But these inserts needs to be across databases. For example from the "Whrs003" database I need to insert data (location_id=123, location_name='markham') in "location" table of "Whrs001" database.

So my thinking is to defined a stored proc which has database name as an argument:
create procedure location_insert
@a_database_name varchar(100),
@a_location_id int,
@a_location_name varchar(50)
as
...

So for the above example the call will be :
exec location_insert 'Whrs001', 123, 'markham'


What would be the actual insert statement in this case? And what things i neeed to take care fo to make sure it always execute successfully?

Thanks

View 5 Replies View Related

Database Variable

Oct 2, 2006

Hi, I have a sql script that references a database explicitly, but the name of that database changes. Rather then have to find anywhere I reference that database and change it, i would like to just set it in one spot. For example.SELECT * FROM [V1_Database].[a_table]I then decide to upgrade from V1 to V2.Instead of having to find the above code in all of my stored procs and manually change it, I would like to do the following.SET dbName = 'V2_Database' (Database wide variable)SELECT * FROM  [dbName].[a_table]But I don't want to have to make all of the places that reference a specific database into string executions. ( strSQL = 'SELECT * FROM [' + dbName + ']' )I hope i havent made this too confusing, but any help is appreciated. Thanks,Brian

View 1 Replies View Related

Best Place To Put TempDB

Nov 16, 2001

Hi,

Can anyone give me any input on this. Recently TempDB one of my production server came down because tempDB got so big that it chewed up all the space in it's drive. My TempDB was in drive C:, where the Operating system and the rest of the SQL systems databases are(msdb,model,master). The actual production data are located in another logical RAID 5(Drive E:) Drive. I want to prevent the problem from happening again. Is it wise or does it degrade performance if i move TEMPDB from drive C: to drive E:? Is this going to cause a major bottom neck in drive E:, where the data are located?

Thank You for any help!


Eric

View 1 Replies View Related

Sql Box Moved From One Place To Other

Jan 5, 2006

what happens if the physical location of a box(which had sql server 2000 on it) is chaned.
what happens to the replication and distributed queries.
Thanks.

View 1 Replies View Related

No Place On Disk

May 20, 2004

I have one big db and i heve no place on disk
the log file is big too. how can i delete the log

View 7 Replies View Related

Best Place To Start

Apr 17, 2007

I am fairly versed with SQL 2005 as I have been using it since it came out. Now I have need to learn about Cubes.



Does anybody have any suggestions of where I need to begin to learn about what cubes are, how to create them and use them?



Ultimately we will be incorporating them into Reporting Services.



Thanks for the information.

View 3 Replies View Related

Where To Place An Order By

Dec 26, 2007

Where would i place an orderby my DateCreated field...everywhere i try to place it i get this error...
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified. Any help with this issue would be greatly appreciated....



CREATE PROCEDURE GetTimeCard

( @LoginID nvarchar(50),

@DateRangeFrom datetime,

@DateRangeTo datetime

)

AS

BEGIN

IF ( @DateRangeFrom = '1/1/1753' ) AND ( @DateRangeTo = '1/1/1753' )

select x.*, x1.TotalExpenses, x2.WorkedCount

from (

select tc.TimeCardID, tc.DateCreated,tc.DateEntered, oe.FirstName, oe.LastName

from OPS_TimeCards tc

join OPS_TimeCardExpenses tce on tc.TimeCardID = tce.TimeCardID

join OPS_Employees oe on oe.EmployeeID = tc.EmployeeID

where oe.LoginID = @LoginID

group by tc.TimeCardID, tc.DateCreated,tc.DateEntered, oe.FirstName, oe.LastName



union

select tc.TimeCardID, tc.DateCreated,tc.DateEntered,oe.FirstName, oe.LastName

from OPS_TimeCards tc

join OPS_TimeCardHours tce on tc.TimeCardID = tce.TimeCardID

join OPS_Employees oe on oe.EmployeeID = tc.EmployeeID

where oe.LoginID = @LoginID

group by tc.TimeCardID, tc.DateCreated ,oe.FirstName,tc.DateEntered, oe.LastName ) x

left outer join (

select tc.TimeCardID, tc.DateCreated,tc.DateEntered, sum(tce.ExpenseAmount) as TotalExpenses

from OPS_TimeCards tc

join OPS_TimeCardExpenses tce on tc.TimeCardID = tce.TimeCardID

join OPS_Employees oe on oe.EmployeeID = tc.EmployeeID

where oe.LoginID = @LoginID

group by tc.TimeCardID, tc.DateCreated,tc.DateEntered ) x1 on x1.TimeCardID = x.TimeCardID and x1.DateCreated = x.DateCreated and x1.DateEntered = x.DateEntered

left outer join (

select tc.TimeCardID, tc.DateCreated,tc.DateEntered, count(*) WorkedCount

from OPS_TimeCards tc

join OPS_TimeCardHours tce on tc.TimeCardID = tce.TimeCardID

join OPS_Employees oe on oe.EmployeeID = tc.EmployeeID

where oe.LoginID = @LoginID

group by tc.TimeCardID, tc.DateCreated, tc.DateEntered) x2 on x2.TimeCardID = x.TimeCardID and x2.DateCreated = x.DateCreated and x2.DateEntered = x.DateEntered



ELSE



select x.*, x1.TotalExpenses, x2.WorkedCount

from (

select tc.TimeCardID, tc.DateCreated,tc.DateEntered, oe.FirstName, oe.LastName

from OPS_TimeCards tc

join OPS_TimeCardExpenses tce on tc.TimeCardID = tce.TimeCardID

join OPS_Employees oe on oe.EmployeeID = tc.EmployeeID

where oe.LoginID = @LoginID And tc.DateCreated BETWEEN @DateRangeFrom AND @DateRangeTo

group by tc.TimeCardID, tc.DateCreated,tc.DateEntered, oe.FirstName, oe.LastName



union

select tc.TimeCardID, tc.DateCreated,tc.DateEntered,oe.FirstName, oe.LastName

from OPS_TimeCards tc

join OPS_TimeCardHours tce on tc.TimeCardID = tce.TimeCardID

join OPS_Employees oe on oe.EmployeeID = tc.EmployeeID

where oe.LoginID = @LoginID And tc.DateCreated BETWEEN @DateRangeFrom AND @DateRangeTo

group by tc.TimeCardID, tc.DateCreated ,oe.FirstName,tc.DateEntered, oe.LastName ) x

left outer join (

select tc.TimeCardID, tc.DateCreated,tc.DateEntered, sum(tce.ExpenseAmount) as TotalExpenses

from OPS_TimeCards tc

join OPS_TimeCardExpenses tce on tc.TimeCardID = tce.TimeCardID

join OPS_Employees oe on oe.EmployeeID = tc.EmployeeID

where oe.LoginID = @LoginID

group by tc.TimeCardID, tc.DateCreated,tc.DateEntered ) x1 on x1.TimeCardID = x.TimeCardID and x1.DateCreated = x.DateCreated and x1.DateEntered = x.DateEntered

left outer join (

select tc.TimeCardID, tc.DateCreated,tc.DateEntered, count(*) WorkedCount

from OPS_TimeCards tc

join OPS_TimeCardHours tce on tc.TimeCardID = tce.TimeCardID

join OPS_Employees oe on oe.EmployeeID = tc.EmployeeID

where oe.LoginID = @LoginID

group by tc.TimeCardID, tc.DateCreated, tc.DateEntered) x2 on x2.TimeCardID = x.TimeCardID and x2.DateCreated = x.DateCreated and x2.DateEntered = x.DateEntered

End

GO

View 3 Replies View Related

Where To Place Articles

May 30, 2006

I have a design that includes articles that will be searched. Obviously its too slow to put them into fields, and impossible because some have photos or are otherwise html documents. So I want to put pointers to their location.

Two questions. For each deployment, both desktop and web, where is the best place to put the articles. In any folder, or only in an iis virtual folder?

dennist685

View 5 Replies View Related

Passing Value To A Variable From Database

Apr 25, 2008

I am trying to get data from a database through a select statment and I want to pass the return query to a c# string variable. Any idea how can I do this?
 

View 2 Replies View Related

Dynamic/variable Database Name

Oct 8, 2004

Hi guys

I have a trigger which retrieves database names from a table.
I need to use this retrieved database name in another sql insert statement as a variable
e.g. set @mydbname = Select .... from.. (to get the database name)
then..
insert into @mydbname.dbo.emplTable

At the moment it reads @mydbname as the string "@mydbname" not the value the variable holds

I need the database name as a variable because i have to write to the correct database (there are 15)
Any help appreciated

Rowan

View 2 Replies View Related

SQL Servers Place In The 'Application'

Jan 28, 2004

I'm rapidly understanding that much more of my application as a whole is in SQL Server that I would have originally thought.

Stored Procedures
Triggers
Constrains
And so on

It generally means that some of the stuff I'd have naturally done in the Business Layer might be best done in SQL - certain issues in the Business Layer might be best being triggers or constraints for example...

One thing that still puzzles me, and I'd like some references or advice now as it's a blank area in my mind is how this interfaces to your asp.net code.

Obviously I call stored procedures and the like from code, and use parameters, etc, not problem, it's more what I do when these stored procedures or associated triggers fail (or a constrain fails - though this should be less likely)?

SQL sends back an error? But what? Then what do you get your page to do, especially if SQL failed midway through a 'big' transaction? Do you have save 'where the user was somehow' so they don't start inputting again?

It's all a bit vague at the moment, some detail would be nice? :)

View 4 Replies View Related

SQL Query Needs Decimal Place

Nov 12, 2005

Hello all,I have an SQL query which retrieves a COUNT number from 2 different tables, and i want to do a division with botht he COUNT data retrieved. Trouble is I can't get it in the format that I want, my SQL query is as below :-SELECT ROUND( ((T1.Present/T2.Total ) * 100), 2) FROM(Select Count(Date) as Present from Attendance WHERE Month(Date)=12 AND Status=1) T1,(Select Count(Date) as Total from Attendance WHERE Month(Date)=12) T2The trouble here is that the result should be as below: T1.Present = 3T2.Total = 5  T1.Present/T2.Total = 3/5 = 0.6The final should be 60 after divided by 100But i am getting a zero as my result, even when I don't multiply the number by 100, the division result is still zero. I am guessing it is a conversion problem. Could anyone please offer me any advise on how to get the final result in the format I want?

View 2 Replies View Related

Place Index On Filegroup

Dec 14, 2001

Hi, I want to replace the indexes in my database to a different
filegroup. How can I do that using T-SQL? I only found a way that
uses the EM, but I have a lot of indexes and I hate to do it manually.

Thanks a lot.

View 2 Replies View Related

Null Error In One Place, But Not The Next

Aug 9, 2001

One of our customers has a production and a test database. We are loading tables via a C++ program that works on production, but not on test, which is supposed to be an exact duplicate.

The error we are getting when trying to add columns to one of the table is 80004e21 null That is it.

When we load the exact same records in the production environment we do not get the error. We have spent many hours ensuring that the tables are exactly the same on test as in production.

Does anyone know, is there an environment variable at a database level that says how to handle null values?

Thanks!!!
C

View 1 Replies View Related

Upgrading From SQL 6.5 To 7.0 With Replication In Place.

Feb 4, 2000

If I have a publisher, distributor, and subscribers all running SQL 6.5, and I wish to upgrade to SQL 7.0, in what order to I upgrade?

View 1 Replies View Related

Best Place To Look For Memory Leak

Jun 21, 2001

Last 2 nights (at night) my SQL Server has locked up, first night trying to back up MSDB(20 meg) and last night ran out of memory at 6:30 AM. No users on at either time, no jobs running on the second night. I was going to turn perfmon on tonite. Any input on what best to monitor?

View 2 Replies View Related

Log Shring When No Place On The Disk ?

Nov 28, 2007

Hello,I run out of space on the disk, my db log is 130GB, I need to shrink db log. I made a backup through network by UNC of the database, but when I want to backup log, I get a message :BACKUP LOG cannot be performed because there is no current database backup.But the backup is reachable, I can restore from it.Any ideas ?

View 8 Replies View Related

Proper Place For Sub Select?

Feb 14, 2013

I have a very simple query that gets a field to use as constraints in another query.

Code:

SELECT A.RIN
FROM apcType T
INNER JOIN apcAttribute a on A.T = T.RIN
WHERE T.Name like '%Sales'

The results of the first query are used in the following query where it is bolded and marked with and <<<<========

Code:
SELECT AP.Arg2, AP.Arg3, M.Parcel,
M.Serial, M.Name, M.Acres, M.District,
V.YearBuilt, V.Code, V.Size,
(SELECT SUM(V1.Acres)
FROM TRValue V1
WHERE V1.Year = V.Year and V1.Parcel = V.Parcel and
SUBSTRING(V1.Code, 1, 1) = 'L'

[code]....

My question is How can I fold the first query into the second?

View 1 Replies View Related

Stored Procedure In Place Of UDF?

Jan 7, 2004

thanks for reading.

i'm wondering if i can use a stored procedure in place of a UDF in the case where i want a return value based on a simple calculation involving the input parameter.

i'd like to use this inline in a query somewhere else. that's why the UDF.

the UDF would be something like this ...

create function getFiscalYear (@when datetime)
returns int
as
BEGIN
declare @rv int

-- months of Oct, Nov, Dec are rolled into following year
if datepart(month, @when) >= 10
select @rv = datepart(year, @when) + 1

-- whereas all other months stay in this year
else
select @rv = datepart(year, @when)
end

END

so, the only reason i'm not using this UDF (and haven't tested it either) is because i can't find (or can't remember how :( ) to add a UDF to my database. when i run this code in Query Analyzer i get an error on the keyword "function". but that's another question altogether.

thanks in advance. (a) for helping with a stored procedure that does the equivalent or (b) nudging me in the right direction towards getting UDFs to work in my SQL 2000 install.

View 5 Replies View Related

Find A Record Out Of Place

Oct 15, 2013

I have a table called Register that has the following in it

Policy_number, Policy_date_time, Portfolio_set, Status..The rule for the table is that the last record for each portfolio_set for a policy the status needs to be 'A' but there have been instances that the last record status is 'I'

I need to identify the record that is out of place..In the example below record number 2.

example

policy_number Policy_date_time Portfolio_set, status
12345 1/1/2011 1 I
12345 1/2/2011 1 A
12345 1/3/2011 1 I
12345 1/4/2011 1 I

I need to identify that the second record is in the wrong place...

View 4 Replies View Related

How To Use A Parameter In Place Of A Literal?

Oct 5, 2007

I have a stored procedure that starts like this:

.
.
.
UPDATE Employees
set depth=0, hierarchy=NULL

UPDATE Employees
set depth=1, hierarchy=right(@MaxPadLength + CAST(Employees.Parent AS varchar(255)),@DisplayPadLength)
where Child = Parent

WHILE EXISTS
(
SELECT *
FROM Employees
WHERE Depth=0
)
.
.
.
I have many tables that have the same structure as the Employees table but have different names. I would like to pass the PS a paramater with the table name I want to process. My question is what is the correct syntax to use a parameter in place of the literals for the table name?

Thanks

View 4 Replies View Related

Insert A Record In A Particular Place

May 27, 2006

i have a table name is HH tableit has two columns 'hhno' and hhname'HH tabelehhno hhname100 suresh101 baba103 rami want to insert a one record(102 , chandra) in HH table between(101,baba) and( 103 ,ram).how can i insert them please help ,me thanks

View 10 Replies View Related

Sorry For The Low Skill Qustion, Maybe It's Not The Right Place

Sep 28, 2007



How am I configuring permission for an SQL database, that user within my program should'nt read private information?

as well how can I protect my database with a UN & PWD to allow access only for authenticated users, not within the program, just the *.mdf file?

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved