Solved

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

Posted on 2012-12-26
1
362 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

724 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