Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need help to update based select statement

Author  Topic 

Idyana
Yak Posting Veteran

96 Posts

Posted - 2014-07-07 : 17:42:41
My table and data as following

USE [test_DB]
GO
/****** Object: Table [dbo].[student1_H] Script Date: 07/08/2014 05:40:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[student1_H](
[idx] [int] IDENTITY(1,1) NOT NULL,
[studentID] [int] NOT NULL,
[first_nme] [nvarchar](50) NULL,
[last_nme] [nvarchar](50) NULL,
[dob] [date] NULL,
[email] [nvarchar](50) NULL,
[complete] [bit] NULL,
CONSTRAINT [PK_student1_H] PRIMARY KEY CLUSTERED
(
[studentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[student1_H] ON
INSERT [dbo].[student1_H] ([idx], [studentID], [first_nme], [last_nme], [dob], [email], [complete]) VALUES (1, 1925, N'', N'james', CAST(0x7D140B00 AS Date), NULL, NULL)
INSERT [dbo].[student1_H] ([idx], [studentID], [first_nme], [last_nme], [dob], [email], [complete]) VALUES (2, 4474, N'susan', N'bahar', NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[student1_H] OFF




This is my select statement,
select * from
(select * from student1_H
where studentID=1925) A1
where
/*filter*/ first_nme='' or first_nme is null or email is null



I want to update field complete to 'false'. How to do that based on my select statement??

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-07-07 : 18:16:00
[code]update
student1_H
set
complete = 0
where
studentID=1925
AND
(
first_nme=''
or first_nme is null
or email is null
)
[/code]
Go to Top of Page
   

- Advertisement -