|
I want to copy a table (not rename - the original table should remain as it is) with all the data in it to another table. Is there any way to do it inside a stored procedure in MS SQL Server?
Thanks
Thomas George
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Highlight the table and select All Tasks -> Export. This will bring you into DTS. Select the Source and then the Destination (in this case they will be the same). Select Copy Table(s), hit next, select the table you want from the source drop-down and then type in a name for the destination table. You can use Transform here to manipulate the fields, etc. Hit Next, you can run this imediately or save in which you can call this DTS Package from a Job, Stored Procedure, etc. (See BOL about calling DTS packages from an sp.)
Another way:
Select * into (new_table_name) from (old_table_name)
This will create a new table with all the info. (NOTE: This 'transfer' is not logged as a transaction, thus can not be rolled back. I believe you can check FULL RECOVERY on you DB and this will correct this.)
Good Luck!
|
|
|
|
|
I have recently installed both SP5 and the Processor Pack to visual C++ 6 and I am having the following
problem. When an exception occurs inside a try catch block inside a function that calls ado methods
the function crashes (in the debug build) on return. The following code runs fine when compiled with
an earlier service pack and no processor pack, but with SP5 + Processor Pack it crashes during the return
from the test function. Also if I compile it on a pc with an eariler sp, it will debug and run fine
on a machine with the latest sp (as long as you don't try to compile!).
The following code has been reduced to the smallest part that I could get it to crash. I compiled it
as a Win32 console application and did not change any of the default values. In SP5 + processor pack
an access violation occurs when test() returns. This was tested on win2k. I compiled and tested it in
debug build only.
#include "stdafx.h"
// You must change this to match your path
#import "D:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename( "EOF", "adoEOF" )
void test()
{
_RecordsetPtr pRst = NULL;
try
{
throw "a";
pRst->Open(_variant_t(), _variant_t(),adOpenStatic ,
adLockReadOnly, adCmdText);
}
catch (...)
{
}
}
int main(int argc, char* argv[])
{
test();
return 0;
}
My question is 1) Has anyone seen this problem? 2) am I doing something wrong?
|
|
|
|
|
your code where you have
throw "a";
looks well dodgy !!!!
maybe you should remove that
|
|
|
|
|
Hi all.
I'm looking to read a flat/fixed width text data file with ADO. I'm assuming that i'll have to write a Schema.ini with all the field definitions in before hand.
Is this correct?
Also, the nice Fixed with import wizard in Access, is there anyway to automate this? I.e., me use it in my app?
Thanks! Pete
|
|
|
|
|
Hi, I was wondering if there was any way I could check for the existence of a field in a table without poking the database and handling an error. I'm sure there is a way, but all my searching has led to no avail.
|
|
|
|
|
use the FieldsPtr class
e.g.
FieldsPtr ptrFields = NULL;
FieldPtr ptrField = NULL;
ptrFields = m_pRS->Fields;
int nCols = ptrFields->Count;
FieldPtr ptrField = NULL;
_variant_t vCol((long)-1);
for (int i = 0; i < nCols; i++)
{
vCol.lVal = i;
HRESULT hr = ptrFields->get_Item(vCol, &ptrField);
if(FAILED(hr))
_com_issue_error(hr);
if ((LPCSTR)ptrField->Name == "My Field")
{
}
}
|
|
|
|
|
Hi!!
I am using ASP-script and an access-database. I want to make a select query
that shows all the data in many tables how is it possible to do this?
An example:
I want to see the names of all companys in the company-table and I also want
to see their adresses wich are in the adress-table and I also want to see
their email-adresses wich are in the email-table. But I also want to see
the companys who do not have for example an email-adress. How is it possible
to extract this kind of data?
/Martin S
|
|
|
|
|
Select
Company.Name, Adress.Adress, email.email
From
Company, Adress, email
where
Company.ID = Address.id And
Company.Id =* email.id
You Understand. The secret is the =*.
But You can use *= depends de case.
I need to clarify something. The =* is a RIGHT JOIN and the other is a LEFT JOIN. In some databases engine =* or *= are no soported, in that case you need to Use the syntax LEFT|RIGHT JOIN.
Test if don't work please notify me, that Y will help you.
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
Thanks for your answer Carlos;)
But since I am using an Access database it does not seem to work by using "*" sign. I would be grateful for other suggestions!!!
Best regards/ Martin
|
|
|
|
|
No problem
In Access you Have the LEFT JOIN and the RIGHT JOIN syntaxis
Like this:
FROM
Company LEFT JOIN email ON
Company.ID = email.companyID
This expession assums that you have Company that don't have email. If a company don't is in the table email the company is showed.
In others words: It selects all companys, including those without email.
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
Hi & Thank you!!!
But how do I do if I have Many tables that I want to join. For example.
I want to see all companies including companys without email and also including companys without telephonenumber etc. Will I need some sort of nested join-query to do this? if so What how shall I write this?
Thanks in advance, Martin
|
|
|
|
|
Is the same
Select Company.*, email.email, phone.phone
FROM
Company LEFT JOIN email ON
Company.ID = email.companyID AND
Company LEFT JOIN phone ON
Company.ID = phone.companyID
If the phone or the email for that company don't exist, you will see the field like NULL.
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
Working in MS ACCESS, developed a small database to track some dept. specific data for projects (nothing big). While working, I have somehow managed to make the Field List Editor disappear.
Clicking the toolbar button and/or the menu item that normally "re-displays" the field list editor, does NOT make the editor visible. I found something in the ACCESS help system that indicated something about piviot tables causing this problem, but I'm not using piviot tables in my project; anywhere.
Does anyone know how to get the field list back?
TIA.
D.
|
|
|
|
|
For the last month i have studing OLE DB with ATL and the ATL wizard in Visual studio c++.
I have Read severals articles about connecting to a database with CCommand and Caccessor and making SQL questions under DEFINE_COMMAND......
All this articles reflects a DB with only one Table. When you then wont to connect to several tables making SQL question, how do i do that?
Is it not possible or what? It must be, or else i think the ATL class for OLE DB is useless.
/Bigge
|
|
|
|
|
Just like with anything the wizards are a good start, but you must be able to add to what has been provided. The ATL OLE DB wizard only works with one table soyou will have to hand code the Accessor to provide for the additional tables.
|
|
|
|
|
I'm learning how to use the ATL templates to access a database. I can read from the table with no problems at all. Unfortunately I can't insert.
I read somewhere that an insert into an empty table can be trouble. Any suggestions.
|
|
|
|
|
What is the problem with the insert? Do you get errors or just empty records? Do you have the update property set?
|
|
|
|
|
I checked further today. The open statement fails when I have the insert, update or delete property set, but works when opened for reading.
I am using the Oracle OleDB driver from Microsoft. I'm wondering if it is a Read-Only driver????
Brad
|
|
|
|
|
Hello,
Is there any way to "select distinct" after deriving a CRecordSet class? I have a rather large table that has a small number of distinct values I'm looking for. Using "select distinct" works well when I query the database using a database viewer, but I'm not sure how I would do this in the derived CRecordSet class. Is there a way?
Thanks in advance!
Derek
|
|
|
|
|
Using CRecordset::Open();
in the second parameter you can write your sql string.
Open(CRecordset::dynaset, "Select Distinct * from table where...");
Cheers!!!
Carlos Antollini.
|
|
|
|
|
What if I already have a derived CRecordSet class like:
class CEmployeesRecordSet : public CRecordSet
{
...
}
Is there anyway to do it from this class?
|
|
|
|
|
If you can't answer that question yourself you need switch to VB or other languages where you won't hurt yourself.
|
|
|
|
|
Yes, You don't have problem with that.
You only need to use the open method in your class. Your class is derived from the CRecordset class, is for this that you don't have problem.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
I want the AAID to be the BBID but this aint working!
DECLARE @sune int
SELECT @sune = MAX(AAID) FROM TEST_SESSION
INSERT INTO CAB_TEST
(BBID, CabComment, CabName, CabFNum, CabFName, CabSNum, CabEmp, CabRefDes)
VALUES(@sune, Null, 'Kabel1', '222-221', 'Styrkabel', Null, 'Chassi', Null);
Plezz Help
/Bigge
|
|
|
|