?
Solved

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

Posted on 2012-12-26
1
Medium Priority
?
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

800 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