|
Oh sorry man, its Change Data Capture , somehow I am able to reach it with SQL coding but if I can capture the column names only with the some settings it will be easier.
Thanks in advance buddies
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 17-Mar-16 20:32pm.
|
|
|
|
|
Sorry for a stupid question.
I am desgning a new DB in SQL server.In this i have a table for example TBLData1 that contain 10 field.and a table TBLUser.
User login from my ASP website can change the data in the table TBLData1.And I Want to record all the log in order to know exactly who has change anything and when this action is happen.
In my opition I create another table TBLData1_Log it have ten field same in TBLData1 and some more field like this:
ID_USer.
Date_Change.
Reason_To_Change.
..........
Any time user change the data at the table TBLData1. It will store the old value to TBLData1_Log and added some more field.
I am wondering if this design is ok? Because the more table, the more log table in my Design.
Please help me to design better.
THanks.
|
|
|
|
|
Why would you duplicate all the data from one table in the log table? Use key values, or just save the userid (or whatever you use as identifier) and the transaction details. Then when you want to print a report you can lookup the user's details by the identifier.
|
|
|
|
|
We use triggers spit to populate the following table. IMHO this is the only valid use of triggers spit. This also services all tables that are being audited.
CREATE TABLE [dbo].[AuditLog](
[AuditID] [INT] IDENTITY(1,1) NOT NULL,
[Action] <a href="1">CHAR</a> NULL,
[TableName] <a href="128">VARCHAR</a> NULL,
[PrimaryKeyField] <a href="1000">VARCHAR</a> NULL,
[PrimaryKeyValue] <a href="1000">VARCHAR</a> NULL,
[FieldName] <a href="500">VARCHAR</a> NULL,
[OldValue] <a href="8000">VARCHAR</a> NULL,
[NewValue] <a href="8000">VARCHAR</a> NULL,
[ModifiedDate] [DATETIME] NULL DEFAULT (GETDATE()),
[UserName] <a href="200">VARCHAR</a> NULL
) ON [PRIMARY]
Actions being Add,Edit,Delete
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
|
Just after opinions here: which of these would be the best practice for an SQLite database:
DELETE FROM Messages WHERE Account = @acct AND NOT EXISTS (SELECT * FROM temp.IdList WHERE MailId=Id)
or
DELETE FROM Messages WHERE Account = @acct AND Id NOT IN (SELECT MailId FROM temp.IdList)
Indexes exist for both Messages(Account, Id) and temp.IdList(MailId)
Each table may hold in excess of 20000 rows
From what I understand, the correlated exists will need to be evaluated for each row of the Messages table, but will stop evaluating as soon as it finds a match (and being indexed, should be pretty quick). However, with the IN expression, the full result set is evaluated only once, but the comparison will be against that full set.
Cheers,
Mick
|
|
|
|
|
Just going by your analysis, I would say the NOT EXISTS would be better. As you say if the table is indexed it should be pretty quick.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I cannot speak for SQLite however I can for SQL Server(which perhaps does not help very much here).
It is best to never use a NOT IN statement, where the results returned could contain many rows, as it will need to evaluate for every single row in the inner select.
Whereas with a NOT EXISTS or a LEFT JOIN with a IS NOT NULL condition, which is another option, it will evaluate as false as soon as it hits the first row where there is a match.
So basically I agree with your evaluation - for what it's worth I always use NOT EXISTS nowadays.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
|
NOT IN and NOT EXISTS are not directly comparable since they treat nulls differently. EXISTS returns TRUE or FALSE only, IN is trivalent and returns TRUE , <code> FALSE or NULL .
Use the one that gives you the result you expect. (Most probably NOT EXISTS )
|
|
|
|
|
Ok guys - I guess the verdict's in. It's what I thought initially thought would be the case too. Its just that the doco on Correlated vs Uncorrelated sub-queries threw me a little, where correlated sub-queries are re-evaluated for each row of the main query. I do agree, however, that re-evaluating the sub-query will be significantly better than searching the full result set.
Cheers people.
|
|
|
|
|
Hi All,
I am trying to write a SQL Query data on to Excel directly, but it is giving me the following error.
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
My code is below
EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 0
INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml; HDR=YES; IMEX=1;Database=C:\Test.xlsx;',
'SELECT [ApplicationName], Date FROM [Sheet1$]')
SELECT [ApplicationName], GETDATE() FROM Application
GO
GO
When initially it gave me above error I copied the excel file to the Server itself and ran the linked server script as below
exec sp_addlinkedserver @server = N'webdevsql1',
@srvproduct=N'Excel', @provider=N'Microsoft.ACE.OLEDB.12.0',
@datasrc=N'C:\Users\AleemA\Desktop\Dont Remove ThisFolder\LocationsExcel\Test.xlsx;',
@provstr=N'EXCEL 12.0;Hdr=Yes' ;
Then ran the script again, now it is giving me little bit different error (ie. Cannot execute the query "SELECT [ApplicationName], Date FROM [Sheet1$]" against OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)").
Can anybody please help me in this regards? any help a code snippet, a link or even a suggestion helps me. I am also searching and trying from online, but if you have already familiar may be your experience helps me. Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 8-Mar-16 14:01pm.
|
|
|
|
|
Hi guys some how I could able to find a way to write selected query values into an xls file but not on the xlsx file yet. If there is a way out for it from somebody can help me, if not for now I will live with it.
But my bigger issue is the below script is writing on to Excel file without headers, can somebody please help me in writing on the excel file along with headers?
Here is my script
DECLARE @cmd VARCHAR(255)='',
@sqlQuery varchar(max) = '"Select top 5 * From WEB_WebAdmin.dbo.Provider"',
@FilePath varchar(max)='"\\dcqwdbs057\Users\AleemA\Desktop\Dont Remove ThisFolder\LocationsExcel\Test.xls"'
SET @cmd = 'bcp '+ @sqlQuery + ' queryout ' + @FilePath + ' -T -c'
Exec xp_cmdshell @cmd
Any help a code snippet, a link or even a suggestion would be greatly helpful, thanks in advance my friends.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
BCP does not support headers, I used to insert the header string with a linefeed into position 0 after the BCP operation.
This also indicates a workaround[^].
All of which is a kludge!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
OK I got an Idea I will create a template file with headers then can I append the contents of the headers file + the output file of the bcp into a final file so that I can have both the headers and content.
Or you can give me how to append row or data in the beginning of the file.
Can you please give me some suggestion or link or code snippet to append header file + content file into a final file using bcp or command shell etc?
Any help is appreciated, thanks in advance I am also searching for it.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 9-Mar-16 12:00pm.
|
|
|
|
|
Thanks buddy, finally at last I could able to do it man !... hah.
Here is my code to do it may be can be helpful to somebody else, first I wrote a query to just print Headers and then query to print content then I appended those two files with cmd shell into one final file
DECLARE @cmd VARCHAR(8000)='',
@sqlContentQuery varchar(max) = '"Select top 5 * From WEB_WebAdmin.dbo.Provider"',
@sqlTemplQuery varchar(max) = '"Select ''WA ProviderId'' WebAdmProviderId, ''WA Last Name'' LastName, ''WA First Name'' FirstName, ''WA Date of Birth'' Dob, '
+ '''PS ProviderId'' WebAdmProviderId, ''PS Last Name'' LastName, ''PS First Name'' FirstName, ''PS Date of Birth'' Dob"',
@ContentFilePath varchar(max)='"\dcqwdbs057\Users\AleemA\Desktop\Dont Remove ThisFolder\ProviderSearchDataMigration\Content.xls"',
@TemplFilePath varchar(max)='"\dcqwdbs057\Users\AleemA\Desktop\Dont Remove ThisFolder\ProviderSearchDataMigration\TemplateFile.xls"',
@FinalFilePath varchar(max)='"\dcqwdbs057\Users\AleemA\Desktop\Dont Remove ThisFolder\ProviderSearchDataMigration\Final.xls"'
SET @cmd = 'bcp '+ @sqlTemplQuery + ' queryout ' + @TemplFilePath + ' -c -C -T'
Exec xp_cmdshell @cmd
SET @cmd = 'bcp '+ @sqlContentQuery + ' queryout ' + @ContentFilePath + ' -c -C -T'
Exec xp_cmdshell @cmd
SET @cmd = 'copy ' + @TemplFilePath +' + '+ @ContentFilePath +' ' + @FinalFilePath + ''
exec master..xp_cmdshell @cmd
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 9-Mar-16 19:55pm.
|
|
|
|
|
But one small limitation here, bcp is creating files only in xls format (97-2003) but any body know how to do the same thing to get document in xlsx format like (2007) format? For now I can live with it but just want to acquire more knowledge on it.
Any help is appreciated, thanks in advance friends
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 9-Mar-16 19:57pm.
|
|
|
|
|
Hi All,
I am migrating data from one table another table in different databases. When source table has line feed and carriage return the destination table is not getting that. All I am doing is inserting the records using select statements.
Can anybody please help me by giving a suggestion how to select columns by preserving line feed and carriage return characters. I am also searching if you know sure that would be helpful.
Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Your code must be doing something to change the data. The SQL should return exactly what is stored in the database for each record.
|
|
|
|
|
Can you share a sample of the code?
|
|
|
|
|
Sorry, yeah it was code issue, thanks for all your support friends.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Sorry for a so stupid question.I am new beginer in C# and ASP.net.
Now I am writing the code for my web connect to database.
I am confuse about the function and procedure.
In VB, I store it in .vb file and then I can call in any form.
How can I do the same in website project asp.net.
|
|
|
|
|
|
Hi All.
I have SQL Server, link to Oracle DB.
In the SQL server I have a T-SQL command
select Moto.ne_code,
Moto.supplier_id,
Moto.ne_type_id,
Moto.sta_datetime,
from PMCALCULATE..[PM_TOOL].[MOTOROLA_CELL_HOURLY_KPI] Moto
and I get the result.
But the sta_datetime in the result is not ok
it is similar to: 2016-02-03 00:00:00 00000000
How to format it to yyyy/mm/dd hh24
|
|
|
|
|