|
Hi All,
I have two different databases on two different servers I compared the source database with destination database, there are few things like a Foreign key doesn't exist in the target database, a couple of columns are missing. Now after finding it, I want to update the schema from Source database to Destination database without losing the data on the target database.
When I ran it, it is giving me error and saying Target database may loose data, can anybody please help me or point me, how can I achieve this?
Any suggestion, link or code snippet can be very helpful. Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
If you are changing column formats or shortening the length of a field you will often get this message. You need to asses whether the changes are actually going to impact your database eg shortening a varchar from 1000 to 500 is not relevant if the longest string is only 100 in length.
Whereas changing a data format from decimal to int may make a critical difference!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
No I am just adding a Foreign key constraint still it errors it out, because in the new database we have added Foreign Key constraint that we want to sync it to the old database without losing the data.
Another place it is erroring out is at a View which is referencing tables from other databases and other servers as well.
Any idea how to resolve these things?
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hi All,
I have a DacPac file that is generated on a server, in which Views are using different Server references and I want to reference it in my Database project as a Database reference.
When I do it, it is throwing following error, can anybody please help me in it, any sort of help, a suggestion, a link or a code snippet would be very helpful.
I am generating the DacPac file from Management Studio and trying to reference it in the SSDT project, lets suppose if it is only because of the version mismatch between SSDT and Management Studio, how can we avoid this mismatch, I am using SQL Server 2008 R2, Visual Studio 2013 and SSDT 12.0, doesn any of these version matter. Any sort of help is greatly appreciated.
And another important thing is my database View are referencing other database, when I went on to that database, the views in that db are referencing another database and when I went into that database the views in that are referencing an another db, like this it goes on, if referencing other dbs is the cause of error, then what can we do to resolve it in those situations. Thank you.
The error is as below:
'C:\Users\AleemA\Desktop\SHP.dacpac' is not accessible or is not a valid schema (.dacpac) file.
Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 19-Oct-15 19:33pm.
|
|
|
|
|
|
Hi All,
I few SQL scripts and in them I am using Table variables to store values from select queries then loop through that table variable to avoid duplicate entries in the tables.
Like
Declare @TabA Table(Id identity, Name varchar, Description varchar)
Insert into @TabA SELECT Name, Description FROM XXXX
Loop through Table Variable using Id and check if that Name already doesn't exist in the TabB then insert else don't.
Now I have interesting question, I am using many inserts in different blocks within same sql script. When I try to declare same Table Variable name again @TabA, it says, it already exists. I don't want to use Drop statement in my script,
1. is there any way that I can make the table variable drop automatically within same script, otherwise do I need to declare different table variable for each insert, if that's the case then wouldn't it be more stress on the RAM as many table variables would exist in the RAM until that whole script runs?
2. I am afraid to use delete on the same Table variable to use it in next insert, For example, if I have to insert into TablC table which has same set of Columns Name and Description, how does Delete works on the table variable would it create Ids from where it left in the before insert or would it create Ids from 1st again?
3 And another question is, if we are running multiple sql files at the same time, do we need to use different table variable names in all of those sql files or the scope of the Table Variable dies soon after each sql file runs?
Please answer these questions any suggestions, links and even code snippets would help me a lot, thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
- Use a different name for each table variable or delete the content and reuse the existing variable
- Why are you scared to use Delete!
- Table variables are limited in scope to the current procedure.
Performance is unlikely to be an issue unless you are processing serious volumes.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Perfect, thank you very much Holmes.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hi,
I am using below code to display times as Pivot table grouped by date, this is basically for fingerprint attendance... I am getting what I want like this:
2012-06-03 10:23:30,10:23:32,10:24:05,10:24:07,10:24:24,10:24:26
How can I make the comma separated values displayed in columns instead of comma so it will be something like this
created_date - time1 - time2 - time3 - time4 --- etc
this is the code:
SELECT created_date, GROUP_CONCAT(created_time)
FROM fingerprint
GROUP BY created_date
Technology News @ www.JassimRahma.com
modified 15-Oct-15 12:52pm.
|
|
|
|
|
Ok, Please HELLLLLP
I have this table with 16 rows only:
http://www.jassimrahma.com/temp/attendence_table.png[^]
and I am using below code now to split the time of attendance into columns and getting this result:
http://www.jassimrahma.com/temp/attendence_result.png[^]
but I am not happoy with it! for example, 7th July, there is only one fingerprint so it should be only F1 but it's repeating it in F1, F3 and F4.
SELECT DATE(attendance_date_time) AS attendance_date, SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 1), ',', -1) AS F1,
IF(LENGTH(GROUP_CONCAT(TIME(attendance_date_time))) - LENGTH(REPLACE(GROUP_CONCAT(TIME(attendance_date_time)), ',', '')) > 1,
SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 2), ',', -1) ,NULL) AS F2,
SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 3), ',', -1) AS F3,
SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 4), ',', -1) AS F4
FROM employee_attendance
GROUP BY DATE(attendance_date_time);
How can I fix this please?
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
anybody can help please?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Hi All,
I have Table A, TabB and TableC, I need to fill TableC by using Select statement and join on TableB and TableA two times. Because TableC is a many to many relationship table on TableA and TableB.
TableA(Id, Name, Desc)
TableB(Id, TableAId, AnotherTableAId, TableAName, AnotherTableAName)
TableC(Id, TableAId, AnotherTableAId, TableAName, AnotherTableAName)
Now the problem is TableA fills the new Data and TableC should be synced to TableB but should have new Ids from TableA and same TableAName, AnotherTableAName values from Old TableB rows. If I run as below, the rows aren't coming correctly, some times more rows than in TableB or some time less rows than in TableB.
Here is how I tried but failed, any suggestion or link or even code snippet would help a lot.
Insert into TableC (TableAId, AnotherTableAId, TableAName, AnotherTableAName)
SELECT TableAId, AnotherTableAId, TableAName, AnotherTableAName FROM TableB b
INNER JOIN TableA a ON a.Name = b. TableAName
INNER JOIN TableA a2 ON a2.Name = b. AnotherTableAName
Please help me with this, thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Look into UNION. Split your query into 2 by removing the second join.
Insert into TableC (TableAId, AnotherTableAId, TableAName, AnotherTableAName)
SELECT TableAId, AnotherTableAId, TableAName, AnotherTableAName FROM TableB b
INNER JOIN TableA a2 ON a2.Name = b. AnotherTableAName
UNION
Insert into TableC (TableAId, AnotherTableAId, TableAName, AnotherTableAName)
SELECT TableAId, AnotherTableAId, TableAName, AnotherTableAName FROM TableB b
INNER JOIN TableA a ON a.Name = b. TableAName
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
I did all of that, thanks for your help and what I felt was to use the Table variable and insert values into it, and then loop through table variable to check if that record combination doesn't exist in the table then insert the set.
I like your approach too.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
I got it Kuldeep, thanks for your support, it is possible by using Merge and Table Variables.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hi,
I am using aloha POS and they have the date for every check in separate fields and now I want to calculate the total time for the checks but unable to get the how of it..
- The date is DOB and it's datetime but I just need to extra the getdate() from it.
- The open time is OPENHOUR and OPENMIN
- The close time is CLOSEHOUR and CLOSEMIN
so basically the open time for the check will be the DATE FROM DOB + OPENHOUR + OPENMIN
and the close time will be DATE FROM DOB + CLOSEHOUR + CLOSEMIN
How can I get the total minutes for the check?
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
This might give you dome ideas, demonstrating the DATEADD and Convert Date possibilities
DECLARE @DOB DATETIME = GETDATE()
DECLARE @ODate DATE
DECLARE @OHour INT = 8
DECLARE @OMin INT = 23
DECLARE @OpenDT DATETIME
SELECT @ODate = CONVERT(DATE,@DOB)
SET @OpenDT = @ODate
SELECT @OpenDT = DATEADD(HOUR,@OHour,@OpenDT)
SELECT @OpenDT = DATEADD(MINUTE,@OMin,@OpenDT)
PRINT @OpenDT
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You can simplify slightly
DECLARE @ODate DATE
DECLARE @OHour INT = 8
DECLARE @OMin INT = 23
DECLARE @OpenDT DATETIME
declare @DOB DATE = getdate()
SELECT @OpenDT = @DOB
SELECT @OpenDT = DATEADD(MINUTE,(@OHour * 60) + @OMin, @OpenDT)
PRINT @OpenDT
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
You've declared @ODate as DATE , so you can't add time parts to it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm adding the minutes to @OpenDT so it does work - @ODate is superfluous and can be removed
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Hi All,
I have a situation that I have 3 tables like TabA, TabB and TabC, I have to insert into TabC by using a select statement from TabB but one value I have to take from Scope_Identity from inserting a row into TabA.
So my Insert should look like below.
Insert into TabC (Col1, Col2, TabAId)
Select Col1, Col2, (Insert into TabA(CurrentDate) Values (DateTime) Scope_Identity) FROM TabB.
So the Scope_Identity of the TabA insert should be used in the Select.
Do we have any way to do it? Any sort of advice, code snippet and link is greatly helpful. Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
You can't embed an INSERT statement within a SELECT statement.
Try something like this:
DECLARE @TabAId int;
INSERT INTO TabA (CurrentDate) VALUES (GetUtcDate());
SET @TabAId = Scope_Identity();
INSERT INTO TabC (Col1, Col2, TabAId)
SELECT Col1, Col2, @TabAId FROM TabB;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This works if we have only one TabAId, but we need multiple TabAIds like different TabAIds for every row that SELECT Col1, Col2, @TabAId FROM TabB; generates, thats my problem. Can you help me pls?
Even if I can use Insert withing Select that's also fine only thing if I can retrieve that Scope_Identity in selected rows.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Or even if I can do it in the following way but I am getting errors in the below query, it is saying its not able to recognize the columns, htge.[Name], htge.[Description]. Can I get those columns into Table variable some how? It will fix all my problems.
DECLARE @MyTableVar table (DocumentListId int, [Name] varchar(max), [Description] varchar(max));
INSERT INTO dbo.DocumentList (CreatedDate,CreatedBy,ModifiedDate,ModifiedBy)
OUTPUT INSERTED.DocumentListId,
htge.[Name],
htge.[Description]
INTO @MyTableVar
SELECT GETDATE() ,CURRENT_USER,GETDATE(),CURRENT_USER, htge.[Name], htge.[Description]
FROM OPENROWSET('SQLNCLI', 'Server=xxx;UID=xx;PWD=xxx',
'SELECT * FROM WEB_WebAdmin.dbo.HealthTopicGroup where HealthTopicGroupId < 45') as htge;
SELECT * frOM @MyTableVar
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|