Currently I have a table in SQL Server 2008 R2 as below
What I'm trying to do is to transform my table into below :
The concept of how it work is value will keep the first Start and End Value, I don't know how to explain this with the word, but if I draw this into the table, it would be like this :
Honestly, I already found a solution for this issue but it only can do with 2 columns, link: SQL: Merge Date Ranges
I am always failing while trying to do this with my table.
Thanks! Appreciate any answer or suggestion!
I think this is what you are trying to achieve.
Select Sites, Min(Range_Start) as New_Start, Max(Range_End) as New_End
from Table_Name
Group by Sites
Related
I am using MS Access 2016 to learn SQL as part of a class on the fundamentals of databases. I am tasked with adding a new column to a table and then populating that column. The column should reveal whether an account is paid in full or if a balance remains to be paid. Based on that criteria it contains only 'Yes' or 'No.' The formula relies on data from two tables (ENROLLMENT and COURSE).
Here are the tables I created:
I have been researching the problem here and on other sites but not finding the logic and only getting syntax errors.
Here are a couple ways I have tried
I am looking for the direction to go to approach the issue and not asking for someone to do the coding for me. Can anyone point me in the right direction?
The following should help populate the column you want to create:
SELECT ENROLMENT.AmountPaid, IIf([ENROLMENT]![AmountPaid]>0,"Yes","No") AS Paid
FROM ENROLMENT;
I have to compare the tables in Server1 database A dbo.X and Server2, database B dbo.Y. Both table X and table Y contains same values.
SO I need to validate both tables contains same values in every row and column. Is it possible to do it?
Thanks
If you do not want to use any Tool like SSIS/Visual Studio then Linked Server will be required.
Select * FROM Server1.databaseA.dbo.X
EXCEPT
Select * FROM Server2.databaseB.dbo.Y
EXCEPT returns distinct rows from the left input query that aren’t output by the right input query.
EXCEPT
Sure, you can do it by creating linked servers. Please, follow this manual to create it:
Creating Linked Servers
After this you will able to make sql-queries to another server like this:
SELECT name FROM [SRVR002\ACCTG].master.sys.databases ;
There is a more easy way if you have visual studio installed. There is a option to compare schema and data with any server and it is very efficient as you can update the target server within the tool as well.
VisualStudio -> Tools -> SQL server -> Data Comparison
I believe there is a new feature where you can define columns as HIDDEN so that a SELECT * returns all except hidden columns.
Is this possible? If yes, how would you achieve it with SQL Server 2016 or SQL Azure?
Adding info from the comments into the answer..
We cant specify a column as hidden and do a select * which returns all columns except hidden like Temporal tables.Moreover this feature is applicable only for validfrom,valid to columns ,though it is nice to have such a feature.As Satya mentioned you can use views to achieve more or less the same.
Currently I'm working on database migration, for this I'm using Pentaho Kettle and Perl scripts.
The migration is from Tumor-registry SQL Server database to CIDER IBM DB2 database.
In this task I want to achieve two objective.
Initial migration: in this I'm migrating all the rows (e.g. 100000) from Tumor-registry (SQL Server) to CIDER (IBM DB2).
Subsequent migration: the Tumor-registry SQL Server database is constantly updating on and off.
It's constantly adding new rows or edits already existing rows.
I have figured out the first step but facing two problems in second step.
a) If Tumor-registry SQL Server database is updated with for example new 10 rows; how can I get those new 10 rows?
b) If already existing 10 rows are updated then how can I get those 10 rows and also want to know which columns are updated.
My Tumor-registry database contain approximately 50 tables.
Any help is greatly appreciated.
Create a new column with TIMESTAMP datatype.This will keep track of the latest edited records in the table.
OR
You can use CHECKSUM function in Sql server.
i think that will provide u a solution by using triger
create triger trigername on tablename
after insert
as
declare #variablename_1 datatype;
select #variablename_1 = column_name from inserted ;
if you want save data in anohter table that last inserted then create an other table
insert into tablename values (#variablename_1);
You could use IBM Change Data Capture, it will take all the DDL and DML in the source database, and replicate them appropiately in the target database.
http://www-01.ibm.com/software/data/infosphere/change-data-capture/
It seems that there are other solutions from other vendors, take a look at: http://en.wikipedia.org/wiki/Change_data_capture
We are evaluating Tableau and noticed that it doesn't appear to recognize sparse columns in our SQL Server 2008 tables. Is this possible or are there any common workarounds?
Yes you can use it like that, the visualization will cut off the parts that are empty, that's all.
Tableau displays the columns it finds from a SELECT * query.
In reviewing this blog we see that SELECT * omits SPARSE columns. https://blogs.msdn.microsoft.com/sreekarm/2009/01/08/sparse-columns-in-sql-server-2008/
You would have to explicitly name the columns you want to see using a CUSTOM SQL connection in Tableau.