General SQL
From Sage CRM Knowledge Base
To get the reference id via SQL you run the code as follows:
Declare @id nvarchar(128) DECLARE @return_value int execute @return_value = [eware_default_values] 'Cases', 'Case_CaseId', 'Case_ReferenceId', 00, @default_value = @id output select id = @id
to run this code in ASP you would have to create the case record using "CreateRecord" and then update the case_referenceid
var _sp='Declare @id nvarchar(128) '+
'DECLARE @return_value int '+
'execute @return_value = [eware_default_values] \'Cases\', \'Case_CaseId\', \'Case_ReferenceId\', 00, @default_value = @id output '+
'select id = @id '+
'update Cases '+
'set Case_ReferenceId=@id '+
'where Case_CaseId=1';
var rec=CRM.ExecSQL(_sp);
If you need to re-create a table (say the triggers are corrupted or not running for example) you can do the following.
Copy a table into new table with/without data - SQL Server
Copy only the structure of an existing table into new table:
SELECT * INTO tblNew FROM tblOld WHERE 1=2
The above query will copy the structure of an existing table(tblOld) into the new table(tblNew).
Copy only the structure with data of an existing table into new table:
SELECT * INTO tblNew FROM tblOld
After this point you will need to drop any indexes and triggers