SQL Tip:
--do Accent Insentitive (AI) and Case Insentitive (CI) join select * from [TableA] a left outer join [TableB] b on a.[AID] COLLATE Latin1_general_CI_AI = b.[AID] COLLATE Latin1_general_CI_AI
A couple of links:
SQL Tip:
--do Accent Insentitive (AI) and Case Insentitive (CI) join select * from [TableA] a left outer join [TableB] b on a.[AID] COLLATE Latin1_general_CI_AI = b.[AID] COLLATE Latin1_general_CI_AI
So how to remove CRLF from a select mycolumn from mytable?
Here is a Catch-All solution:
REPLACE(REPLACE(REPLACE(REPLACE(MyTable.MyColumn, CHAR(13) + CHAR(10), ' '), CHAR(10) + CHAR(13), ' '), CHAR(13), ' '), CHAR(10), ' ')
Thanx to Rex Tang.
But I just want to remove CRLF:
REPLACE(MyTable.MyColumn, CHAR(13) + CHAR(10), '')
Was looking for a Microsoft offer that could give OS’s and Servers to play with at home. Found a few interesting programs:
A datawash solution:
Problem: From Active Directory I had a long list, where column alias was not unique.
Instead of do any manual filtering away the aliases that were found more than once, I just wanted SQL server to throw away the duplets, leaving only one alias bin the list.
(more…)
I was just told not to use
READ UNCOMMITTED also called dirty read in SQL 2008. A new possibilty exists:
READ COMMITTED SNAPSHOT
The problem with the first one is that if conn A reads a large bit, conn B do update, conn A reaches the updated bit and reads that, conn B rolls back, then conn A got illegal data.
If using the snapshot read, then conn A reads only on a snapshot as long as conn B is doing update. This snapshot contains the before transaction data.
This makes sence because had connection B just been a little later, then it would have been the same situation as with the snapshot option.
Thanks to Jesper Johansen
A little trick to create a OLEDB connection string:
Examples of generated connection strings:
Thanx to Rakesh Moturi
The End
This post shows how to use the SSMS GUI to attach a DB.
1) Download Adventurworks from http://www.codeplex.com/Wiki/View.aspx?ProjectName=SqlServerSamples
2) Install the DB. This will only unpack the mdf file.
3) Attach the DB. Then you can see it in SSMS:
You can either use commands like here: http://www.codeplex.com/SqlServerSamples/Wiki/View.aspx?title=SQLServerDatabasesandSamplesOverview&referringTitle=Home
Or you can browse for the mdf file:
Where to find Object Created date?
In SSMS have open Object Explorer and Object Explorer details.
The details view of the latter will show created date.
Thanx to Kim Bach
You can also use a query:
USE AdventureWorks; GO SELECT name, create_date, modify_date FROM sys.objects WHERE type = 'P' AND name = 'uspUpdateEmployeeHireInfo' GO
Thanx to Pinal Dave
The end
Wants to visit BarCamp Copenhagen. The idea is to share knowledge. This forces me to find some topics to precent…
So what is a topic I can present to catch other peoples interest? Luckily I have started blogging. WordPress (wp) gives me the answer. Wp has a statistics page. You will not be able to follow that link, since you need admin rights. (more…)
Terminology:
PreRequisites:
Now use the following join to add new rows from the flat file to the domain table.
Note: In this example the Domain table uses a varchar as ID.
Insert Into TargetDomainTable (ID, Name) -- targettable Select Distinct IT.TTID, IT.TTName -- data from importtable From ImportTableTemp IT -- importtable Left Outer Join TargetDomainTable TT On IT.TTID = TT.ID -- all rows from importtable Where TT.ID is NULL -- targettable has not data AND IT.TTID is not NULL -- importtable has data AND IT.TTID != '' -- importtable has data (optional - when TTID is a varchar)
I never thought SQL server backup was easy to remember.
This is probably because the restore command involves 3 physical files, 2 logical names and the Db name. (more…)
I guess I am not the only one, who thinks the SQL user account setup is a strange mess. (more…)
One of the big advantages with LINQ is that you can do operations on sets in the data access layer instead of doing them in the database.
An example of this is to join a table from a CSV-file with a table in a database. In this example the CSV-file has been loaded into a List(Of CsvRecord), where CsvRecord is an entity object representing the content of the file. Code for that class contains properties for each column. The code is not shown here. For this example it just contains the property CsvId, which is used for joining with the SQL server.
Update of the resultset back to SQL server is possible and easy (Wow), but not shown in this post. (more…)
Simple update/insert sample – just nice to have
-- Update MyTable, when ID is known if (select count(*) from MyTable where MyId = @MyId) > 0 UPDATE MyTable SET MyColumn = @MyColumn WHERE MyId = @MyId else --exec add2MyTable @MyId, @MyColumn INSERT INTO MyTable (MyId,MyColumn) VALUES (@MyId,@MyColumn)
Under master you will find a sp for reindexing. It has different parms, so go there and check them first.
exec sp_sk_reorgDB myDb, 0 , 'Y'
From http://www.webservertalk.com/archive132-2004-3-145797.html :
If you are running SQL 2000, another technique is to create an indexed view
to enforce your unique-if-not-null constraint. For example: (more…)
SP_COLUMNS view_employe
npr dbo VIEW_employe employestate 5 smallint 5 2 0 10 1 NULL NULL 5 NULL NULL 2 YES 38
<span style="font-size: x-small; color: #0000ff;">SELECT</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff00ff;">@@SERVERNAME</span>
select firstname + ' ' + lastname as [name], count(*) as counter from employe group by firstname + ' ' + lastname having count(*) > 1 order by counter desc, [name]
-- output name counter ----------------------- ----------- Hallo World 82 Jens Jensen 21
http://www.thescripts.com/forum/thread81525.html
-- If a search string can be null if @shortaddress is null select @addid = addid from address where shortaddress is null else select @addid = addid from address where shortaddress = @shortaddress -- can be replaced with select @addid = addid from address where isnull(shortaddress,'@£$' ) = isnull(@shortaddress,'@£$' ) -- (where '@£$' is a value, which is not possible to get in that column)
-- Find those addid in the employe table, which is not in the address table: select addid from (select distinct addid from employe) e where addid not in ( select a.addid from address a inner join (select distinct addid from employe) e on a.addid = e.addid ) -- same as select distinct addid from employe where addid not in (select addid from address) -- nulls can be a problem. If all values are wanted, -- which is not in the address table then use this: select addid from employe where ( addid not in (select addid from address where addid is not null)) or addid is null ) -- then there is also this: -- select de rækker i employe, der ikke er i address tabellen select e.* from employe e left join address a on e.addid = a.addid where a.addid is null