sql-server-2005

SELECT with a Replace()

浪子不回头ぞ 提交于 2020-07-31 06:57:11
问题 I have a table of names and addresses, which includes a postcode column. I want to strip the spaces from the postcodes and select any that match a particular pattern. I'm trying this (simplified a bit) in T-SQL on SQL Server 2005: SELECT Replace(Postcode, ' ', '') AS P FROM Contacts WHERE P LIKE 'NW101%' But I get the following error; Msg 207, Level 16, State 1, Line 3 Invalid column name 'P'. If I remove the WHERE clause I get a list of postcodes without spaces, which is what I want to

while updating a row: Cannot insert duplicate key row in object 'dbo.tblRelatie' with unique index 'idxRelatiesoortRelatiecode'

烂漫一生 提交于 2020-07-05 10:12:29
问题 when UPDATEing a row I get the above error. idxRelatiesoortRelatiecode consists of fldRelatieSoort and fldRelatieSoort and the combination of both exists only once in the table. So what could be the reason for this error? Update Here is the update script UPDATE [SQL].[MyDatabase].dbo.tblRelatie SET fldNaam = 'De heer A. Removed', fldAdres = 'Removed 12', fldPostcode = '1234 AA', fldPlaats = 'Removed', fldCorrespondentieAdres = 'Removed 12', fldCorrespondentieAdresPostcode = '1234 AA',