|
That's what I'm building at the moment.
But you're quite right, it's not what I wanted to hear.
To many error sources, and yet another place to add the same texts again.
I suspect that this is one of those cases where garbage in becomes garbage out.
|
|
|
|
|
There's a number of ways to approach this.
Sounds like you're at the "exploratory" stage.
In that case, I might suggest MS Power BI for the Desktop.
Power BI Desktop | Microsoft Power BI
You can use Power BI to pull data from multiple sources, build relationships, and get a "feel for the data" and perhaps produce your report in question (with or without using any number of "cleansing" techniques).
Moving forward, look into (data warehouse) "star schemas" for modeling ideas.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Jörgen Andersson wrote: I'm looking for ideas on how to make this in a fairly futureproof way, I don't really have any keys to use either. It's just the column names in one source and the attribute names in the other.I realize there is no right way of doing this (but many wrong).So any opinions on how to do this You got two groups of unsorted and ungrouped column-names coming from a repository that need to be mapped to a model?
..then I'd go for a relational model, even if it only exists in memory. Which would mean following the steps to normalize the data (upto BCNF). That's a tedious but proven way. Any group of properties that make up a model (regardless of the way the data is physically stored) would be a candidate.
I would seriously consider creating that theoretical model and then create an in-memory database (using SQLite or similar) to hold it. The added advantage of that approach is having an abstraction of the data that you can already use to design reporting and stuff. Another added advantage is that any redundancies or inconsistencies in the database would be caught. Downside is that you need (access to) a domain-expert to build and validate the model.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, this would probably be the right way of doing it.
|
|
|
|
|
Jörgen Andersson wrote: Yes, this would probably be the right way of doing it. Not the most exciting thing to do, I agree
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Using Linq-To-SQL. I have this update method. I'm getting a "Specified cast is not valid exception". The line number of the exception is the query line in the inner Try/Catch.
public void UpdateDashboardInfo(AssayDashboardInfoEntity entity)
{
try
{
using (var context = new AssayDashboardDataContext())
{
AssayDashboardInfo model = null;
try
{
model = (from adi
in context.AssayDashboardInfos
where adi.ResultId.CompareTo(entity.ResultId) > 0
select adi).FirstOrDefault();
}
catch (Exception e1)
{
_logger.Error("****** ARD_DAL: UpdateDashboardInfo (Query)", e1);
}
if (model != null)
{
model.SiteId = entity.SiteId;
model.InstrumentId = entity.InstrumentId;
model.TowerLocation = entity.TowerLocation;
context.SubmitChanges();
}
}
}
catch (Exception e)
{
_logger.Error("********** ARD_DAL: UpdateDashboardInfo", e);
}
}
"adi.ResultId" is a DB Guid. "entity.ResultId" is a .Net Guid in my entity class.
Anyone see what's wrong with this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It looks like you're trying to update the entity with a matching ID. But your query is updating the first entity whose ID is greater than the ID of the entity you've passed in.
Does it even make sense to ask if one GUID is greater than another?
I suspect your query should be:
model = (from adi
in context.AssayDashboardInfos
where adi.ResultId == entity.ResultId
select adi).FirstOrDefault();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
ya, should be "string.Equals()"
But I was getting the cast exception BEFORE I added the Compare. I'm guessing that there's some problem comparing a SQL GUID against the .Net GUID
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I tried this query in SQL. But getting errors like
'The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.'
declare cur cursor for Select Table_Name From INFORMATION_SCHEMA.COLUMNS Where column_name = 'INV_DATE'
declare @tablename nvarchar(max)
declare @sqlstring nvarchar(max)
open cur
fetch next from cur into @tablename
while @@fetch_status=0
begin
set @sqlstring = 'update '+@tablename+' SET INV_DATE = CONVERT(varchar(10),INV_DATE,105)'
exec sp_executesql @sqlstring
fetch next from cur into @tablename
end
close cur
deallocate cur
Please suggest me a solution
current format:2016-03-31 00:00:00.000
Required Format:31-03-2016
DataType:DateTime
I tried to copy data and changing to DateTime using temp field.But also getting the same error.
<pre lang="SQL">alter table GL add GL_DATE1 datetime null
update GL set GL_DATE=convert(datetime,GL_DATE,104)
update GL set GL_DATE1=GL_DATE
alter table GL drop column GL_DATE
SP_RENAME 'GL.GL_DATE1','GL_DATE','column'
please give me the advice to copy data from one field to another field using the temp table.
Please
|
|
|
|
|
Why do you want to do that? The datetime format is only matter to human not the sql server. Just leave it as it is as datatime, then format it on select to the appropriate format or culture that suite the users. Learn why you should not bother How to format a Date or DateTime in SQL Server[^]
Peter Leow
http://www.peterleowblog.com/
https://www.amazon.com/author/peterleow
|
|
|
|
|
Ok.I can leave it.At least can u please tell me how to convert that field into datetime by using above query.
alter table GL add GL_DATE1 datetime null
update GL set GL_DATE=convert(datetime,getdate(),104)
update GL set GL_DATE1=GL_DATE
alter table GL drop column GL_DATE
SP_RENAME 'GL.GL_DATE1','GL_DATE','column'
|
|
|
|
|
|
update GL set GL_DATE=convert(date,getdate())
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Still getting error 'Conversion failed when converting date and/or time from character string.' while converting by using your query.
|
|
|
|
|
Which means one of the strings in the source column is not a valid datetime value.
Which is why you should never store dates as strings.
If you're using SQL 2012 or later, you could use TRY_CONVERT[^] or TRY_PARSE[^], which will return NULL for any values it can't convert. Otherwise, you're stuck with converting the values manually.
NB: In your example, you should update the new GL_DATE1 column directly, rather than updating the original GL_DATE column and then trying to copy it across.
You'll probably also want to use the newer datetime2 type[^], which has a better range than the old datetime type.
alter table GL add GL_DATE1 datetime2(0) null;
update GL set GL_DATE1 = TRY_CONVERT(datetime2(0), getdate(), 104);
select GL_DATE from GL where GL_DATE1 Is Null And GL_DATE Is Not Null;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 1-Feb-17 7:58am.
|
|
|
|
|
Got an exception 'datetime2' is not a recognized built-in function name' while running the query as you mentioned.
|
|
|
|
|
So you're using SQL 2005 or earlier? You'll have to stick with datetime in that case.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I need to know which is better for work and performance please :
I have to do many operation on database so I am hesitating between :
- create object "SqlConnection" and let connection opened during service (webservice) works
- using the instruction below every time I want to do a modification in dtatabase
using (SqlConnection sqlconnection = GetSqlConnection(connectionString, false))
{
sqlconnection.Open();
.....
}
Where
public static SqlConnection GetSqlConnection(string connectionString, bool disablePooling = true, bool forceMasterDB = false)
{
if (disablePooling || forceMasterDB)
{
SqlConnectionStringBuilder sqlConnBuilder = new SqlConnectionStringBuilder(connectionString);
if (disablePooling)
sqlConnBuilder.Pooling = false;
if (forceMasterDB)
sqlConnBuilder.InitialCatalog = "master";
connectionString = sqlConnBuilder.ConnectionString;
}
return new SqlConnection(connectionString);
}
Thank you
|
|
|
|
|
If you have the code, why not write a simple app to process a number of statements and check the execution time.
Ensure the statements executed are the same for each.
|
|
|
|
|
thank you for response but as I said I know what you suggest but I ask what is more safe also for me.
|
|
|
|
|
Create the connection as late as possible, and wrap it in a using block to ensure that it's always disposed of properly.
Don't disable connection pooling, since the underlying network connections can be expensive to set up and tear down. The connection pool is there to improve the performance of your code!
Trying to share a single connection object across multiple threads will only lead to errors. To avoid the errors, you'd have to synchronise access to the shared connection, which will significantly degrade the performance of your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank you for response
Yes what I did is that every time I need the connection I use it in using block.
Also I use pooling always because I'm using the same connection string.
so you see this safe ?
|
|
|
|
|
Yes, it sounds like you're doing the right thing.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Hi,
I need regular expressions in SQL Server for two things
- Get the first 3 characters from a string, no matter alphabets or numerical values but not special characters, like for example if I have file name A00Temp then it should give me A00 and if the string is _A00Temp then still it should give me the A00 only but not _A0, if it has ABCTemp then it should give me ABC
- the 2nd need is if I have a string with alphabets, numerical and special characters then it should give me only alphabets from that string
for exmple if I have: Abc def 230 then I should get abcdef, if I the string is _abc$#def then I should get only abcdef.
If I can do this using regular expressions, please help me, any type of help is very welcome, thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|