---
title: "Update"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/175186-update"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "devotion"
published: "2008-11-05T20:36:16.000Z"
updated: "2008-11-06T09:19:08.000Z"
replies: 5
views: 498
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/databaser-sql/175186-update"
---

# Update

## #1 — devotion, 2008-11-05T20:36Z

Hej, 

Jag vill göra en update enligt:

```
Update [tblObject]
Set [Modified] = GetDate(),
      [Name] = [Custom2]
Where [Level] = 0
```

Men om Custom2 är Null eller '' (tom sträng) så vill jag behålla \[Name\]

Hur?

Ms sql

Mvh
Henrik

Permalänk: https://www.webforum.nu/p/175186

## #2 — CatZ, 2008-11-05T21:09Z

```
IF [Custom2] = ''
    Update [tblObject]
    Set [Modified] = GetDate()
    Where [Level] = 0
ELSE
    Update [tblObject]
    Set [Modified] = GetDate(),
          [Name] = [Custom2]
    Where [Level] = 0
```

Permalänk: https://www.webforum.nu/p/2152389

## #3 — devotion, 2008-11-05T21:24Z

Jag sökte runt lite och hittade något sånt här:

```
UPDATE tblObject
SET 	[Modified] = Getdate(),
	[Name] = 
    		( CASE
         		WHEN [Custom2] = '' OR [Custom2] IS NULL THEN
				[Name] = [Name]
         		ELSE 
				[Name] = [Custom2]
       			END
    		)
WHERE [Level] = 0
```

Skulle det fungera?

Permalänk: https://www.webforum.nu/p/2152392

## #4 — devotion, 2008-11-05T21:49Z

Eller kanske bara:

```
UPDATE tblObject SET Modified = GetDate(), Name = Custom2 WHERE Level = 0 And (Custom2 <> '' Or Custom2 Is NOT Null)
```

Typ?

Permalänk: https://www.webforum.nu/p/2152399

## #5 — Peter S, 2008-11-06T08:18Z

Eller

```
UPDATE tblObject SET Modified = GetDate(), Name = Custom2 WHERE Level = 0 And Custom2 <> '' And Custom2 Is NOT Null
```

Permalänk: https://www.webforum.nu/p/2152421

## #6 — devotion, 2008-11-06T09:19Z

Så får det bli....

Permalänk: https://www.webforum.nu/p/2152423

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/175186-update
