Solved

tsql how to update column in all records of a table ..

Posted on 2012-12-26
1
357 Views
Last Modified: 2012-12-26
/****** Script for SelectTopNRows command from SSMS  ******/
SELECT top 2 p.ProgramID,a.ProgramIDM
  FROM [radiomix].[dbo].[chat] a
 inner JOIN [radiomix].[dbo].[MixFmProgram] p ON (a.DAY = p.ProgramWeekDay)
   WHERE 
  CONVERT(varchar,[datetimein], 114) >= convert(varchar, CONVERT(datetime,p.ProgramStart), 114)
and CONVERT(varchar,[datetimein], 114) < convert(varchar, CONVERT(datetime,p.ProgramEnd), 114 )
 order by a.id desc

Open in new window


this is the querry
i want to update all p,ProgramIDM to the a.ProgramID


iin this example i have selected only 2 record order by a.id desc
i want to update the value of programidm in table chat by the correct one ??
what should be the query ??
0
Comment
Question by:afifosh
1 Comment
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 38721298
Something like this perhaps:
UPDATE a
SET     ProgramIDM = p.ProgramID
FROM    [radiomix].[dbo].[chat] a
        INNER JOIN [radiomix].[dbo].[MixFmProgram] p ON (a.DAY = p.ProgramWeekDay)
WHERE   CONVERT(varchar, [datetimein], 114) >= CONVERT(varchar, CONVERT(datetime, p.ProgramStart), 114)
        AND CONVERT(varchar, [datetimein], 114) < CONVERT(varchar, CONVERT(datetime, p.ProgramEnd), 114)

Open in new window

0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now