|
If you are using SQL Server 2000, you would rename it using the sp_rename method. Suppose that you are renaming a table called MyTable to My_Table, you would run exec sp_rename 'MyTable', 'My_Table' .
It is important for you to be aware though that this is a very dangerous operation to undertake and you shouldn't do so lightly. When you rename an object like this you don't get any form of dependency checking and, as a result, anything that relies on the table being called MyTable will fail. Some areas that you would need to check include your stored procedures, views, functions. Don't forget to check your DTS packages as well - I've lost count of the number of times I've seen DTS packages failing because somebody renamed a table and didn't bother to update the mappings inside DTS.
Finally, make sure that you don't expose this functionality to the outside world. Do not, under any circumstance, allow any client code to do this - it WILL break things.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
If I have a query like
select bkID, count(*) from SalesLog where SaleDate = '20070410' group by bkID compute sum (count(*))
and if I had called it via a vb application is there any way I can get the value corresponding the sum?
|
|
|
|
|
hi all,
i m using Access 2007. if i create an query which use replace function and execute directly then it execute successfully in database .but if i run same query through application then it give error "Undefined function replace in expression".
i don't know where i am wrong ?
query is following
UPDATE master SET titles = replace(titles,'Trainer','Rupesh');
any body have idea or some suggestion ?
thanks in advance.
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
For security reasons, MS Access only permits a handful of functions to be called from an application outside of Access itself. I'm guessing that's the problem, but honestly, don't know if the "Replace()" function is on the forbidden-list.
Before I knew about this issue, I spent a lot of time writing VBA functions and using them within my queries, only to discover that none of the functions I wrote could be accessed from an outside application. Every query I called from the outside application that used one of my functions failed. I had to completely abandon the application and start over with an Access application.
Actually, I did do some googling looking for the list of functions allowed, but couldn't find it. Maybe some other reader knows where it is.
I don't understand how all this works, but try going to Access, Tools->Macro->Security, and select "Low" and see if that helps. If not, then I would restore the setting to it's previous setting.
David
|
|
|
|
|
Hi all
I am trying to use xp_SendMail from a stored procedure and it keeps failing with an error message about not specifying a parameter for @recipients when obviously I have specified it.
Sample
CREATE PROCEDURE<br />
...<br />
IF error GOTO ERROR<br />
...<br />
RETURN<br />
<br />
ERROR:<br />
exec master.dbo.xp_SendMail @recipients = "bla@here.com",...<br />
GO
If I move the xp_SendMail statement to between the Create procedure and Return statements (copy and paste) it works, it only does not work when it's in the 'ERROR:...GO' section.
Anybody please...Deadlines are aproachin'
Kiefie
The man with a plan. Now where'd that plan go?
|
|
|
|
|
So I have a table of teams, orgTeams, each of which has a primary key, teamID.
I have a table of users, orgUsers, each of which has field that describes what team the user is on, userTeamID.
If I want to get a list of all of the teams that have at least one person on them, it is easy:
SELECT DISTINCT teamID FROM orgTeams,orgUsers WHERE userTeamID=teamID
However, with people moving from team to team, sometimes teams end up "empty", i.e. with nobody at all on them. What query can I use to identify such "empty" teams?
|
|
|
|
|
To determine if a table has rows in it you can use
SELECT COUNT(*) FROM tableName
ie. ( I think)
SELECT DISTINCT teamID FROM orgTeams,orgUsers WHERE userTeamID=teamID and COUNT(orgTeams.Person) > 0
Kiefie
The man with a plan.
|
|
|
|
|
I understand the COUNT() function, but I don't understand what orgTeams.Person is supposed to refer to in your example. I don't have a "Person" field in my table orgTeams.
|
|
|
|
|
I don't know what fields you have in your table so I made it up. Could work with just about any field. I see there are more posts which will probably work better.
Kiefie
The man with a plan.
|
|
|
|
|
You could probably do this with:
select distinct teamId
from orgTeams
left join orgUsers
on teamID = userTeamId
group by userTeamID, teamID
having count(userTeamID) = 0
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
select teamId
from orgTeams
left join orgUsers
on teamID = userTeamId
where userTeamId IS NULL is equivalent and likely to execute quicker.
|
|
|
|
|
True - this is what happens when you code when tired. You end up overcomplicating things. Thanks for pointing this out to the OP.
I'd like to think that I would have spotted this, this morning.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thank you! This worked perfectly.
|
|
|
|
|
I have 2 tables. I want to use info from the second table to update column values in the first. Consider:
T1:
id time1 time2
1 8:00 null
2 8:01 null
3 8:02 null
4 8:12 null
T2:
id time2
2 8:09
4 8:15
What I want is:
T1:
id time1 time2
1 8:00 null
2 8:01 8:09
3 8:02 null
4 8:12 8:15
Is there an sql command sequence that can achieve this? Its easy to think about it iteratively, but in the absense of explicit iterators in sql (to my understanding) I hope that there's another way.
Its clear that I can exec the join:
select T1.id, T1.time2 from T1, T2 where T1.id = T2.id
but using this as part of an update is broken (well, because I don't know how to do it):
(wrong
update T1
set time2 = ( select time2 from T1, T2 where T1.id = T2.id)
where id = ( select id from T1, T2 where T1.id = T2.id )
how can I write an <update> on T1.time2 that matches T1.id = T2.id and updates the T1.time2 null with the T2.time2 ?
|
|
|
|
|
UPDATE T1
SET time2 = T2.time2
FROM T2
WHERE T1.id = T2.id Tested with SQL Server 2000 SP4.
You basically have an implicit cross-join with the table you're updating and the tables and join statements listed in the FROM clause.
|
|
|
|
|
Hi,
I need to do a check on a date field in my table, I need to check if the entered year is in the publication date. Currently I have it like this:
SET ROWCOUNT 500;
SELECT *
FROM tblFullTextSearch
WHERE
fldPublicationDate LIKE (1995);
The reson why I used like is because the user can type any number into the date input textbok. The date in the table looks like:
1995-03-01 00:00:00.000
Please can someone help.
Regards
ma se
|
|
|
|
|
SET ROWCOUNT 500;
SELECT *
FROM tblFullTextSearch
WHERE
YEAR(fldPublicationDate) = 1995;
|
|
|
|
|
You can do that, but SQL Server cannot make use of any indexes on the fldPublicationDate column. If the year is what's wanted, you can do
SELECT *
FROM tblFullTextSearch
WHERE fldPublicationDate >= '19950101' AND fldPublicationDate < '19960101' Obviously this technique does not work if you want to find all records from March, or the first day of the month, for example.
|
|
|
|
|
Hi i need one more query...,
See i have records like this:
Id value edate
100 1000 10/13/2006
101 1300 12/21/2006
102 1250 09/19/2006
102 1765 4/28/2007
102 1845 5/4/2007
100 1500 3/21/2007
100 1750 6/1/2007
101 1200 4/21/2007
103 1000 12/12/2006
If i pass the month and year based on it my o/p want to come...,
See its diff from other queries...,
Suppose if i select month=5 and year =2007
My o/p will be:
Id value edate
100 1500 3/21/2007
101 1200 4/21/2007
102 1845 5/4/2007
103 1000 12/12/2006
Means See the above table:
for that id=100 its not taken final date record also and last entry record also...,
Based on the passing month & year,it has taken 3rd month record...,
Same time, see that id=102 taken 5th month record ,its not taken 4 th month record...,
See that id=103 dont have any other date record so its taken which one have value that one...,
Like that i need query...,
If u didnt get what i am asking,i am ready to explain more than this also...,
Advance thanks...,
-- modified at 7:16 Tuesday 31st July, 2007
Regards,
Magi
|
|
|
|
|
in a nutshell,
row with max(edate) for a specific id, less than given Month & Year
is my understanding right
Regards
KP
|
|
|
|
|
Sorry krish ur correct,
See i have modified the query...,
It has taken that equal month record also...,
and see its not taken max(edate)...,
see that id=100 have 6th month 2007 th year record also...,
But it has taken 3rd month record...,
So we cant say max(edate) also...,
Plz if possible give me the query for that...,
Advance thanks,
Regards,
Magi
|
|
|
|
|
Yes for id 100, date with Jun-2007 to be ignored becasue is more than search condition i.e. May-2007.
to be picked up is Mar-2007 with the next higher date.
comming for 102 as per your example
102 1845 5/4/2007
May-2007 data is fetched is it right. should it be Apr-2007 like
102 1765 4/28/2007
pls check is this what you are looking for ...
DECLARE @Mth AS Varchar(5)
DECLARE @Yr AS Varchar(5)
SET @Mth = '5'
SET @Yr = '2007'
SELECT * FROM TblA order by id
SELECT a.*
FROM TblA a
INNER JOIN (SELECT id, Max(Edate) AS Edate FROM TblA WHERE Edate < @mth + '/01/' + @yr GROUP BY id)b
ON a.id = b.id AND a.Edate = b.Edate
ORDER BY a.id
output what i got is
100 1500 2007-03-21 00:00:00.000
101 1200 2007-04-21 00:00:00.000
102 1765 2007-04-28 00:00:00.000
103 1000 2006-12-12 00:00:00.000
-- modified at 8:10 Tuesday 31st July, 2007
Regards
KP
|
|
|
|
|
No krish i didnt get any o/p like that..,
See i have modified my query,i need o/p for that selcted month also...,
For that id=102 it want to display 5th month record not 4th one,
That i have modified...,
Plz send query for like that...,
Hlp me plz,
Advance thanks
-- modified at 9:00 Tuesday 31st July, 2007
Regards,
Magi
|
|
|
|
|
hi,could anyone explain me on how to create columns in sql wen i enter a charcter value in text box?
let say,if i enter A, one column need to be create,if B two need to be created in existing table ....
how can i do this???
thanks for any help!!!
The Best performance for good work tomorrow is to do good work Today
|
|
|
|
|
Need to create a table (CREATE TABLE ...)
and then add columns (ALTER TABLE ...)
refer this url for usage of CREATE TABLE & ALTER TABLE
http://sqlzoo.net[^]
Regards
KP
|
|
|
|