sql-server


Updating one table using information from another


I have two tables:
table one consists of work days and hours worked
table two consists of work locations and starting dates
Using table 2 I am hoping to identify work locations in table 1 (as in desired result column).
You can use APPLY and TOP:
SELECT
t1.*, x.WorkPlace
FROM Table1 t1
CROSS APPLY(
SELECT TOP(1) WorkPlace
FROM Table2 t2
WHERE t1.WorkDays >= t2.Date
ORDER BY t2.Date DESC
) x

Related Links

Web deployment task failed. Failed to create type 'Microsoft.SqlServer.Dac.DacServices'
What is the DacServices option to skip deployment of full-text search indexes?
When rowversion column is calculated on SQL Server
What's the columns updating order when several columns are updated?
Failed to open rowset. Details:42000:[Microsoft][ODBC SQL Server Driver][SQL Server]
unique key on two columns commutatively
SQL Count with Inner Join for Single Table
How to use stored procedure with table-valued parameters to compare two input tables
Get items and dates checked in and out by person
SQL Anywhere 16 to SQL Server Migration
SQL Server : reverse engineering view and stored procedure
I imported a CSV into SQL Server and am now stuck with these hideous pipe characters
Reporting Services Configuration Manager - empty instance name
Azure. Automation of tempDB with ARM templates
SQL Server Inequality Comparison Operators, why have two [duplicate]
Sql Server Msg 2110

Categories

HOME
xbox-live
reverse-engineering
nuxeo
uibutton
phpstorm
apple-numbers
algorithmic-trading
yocto
httpclient
metronic
uiview
bootstrap-popover
factor-analysis
grub2
jcl
chocolatey
movies
zoho
jconsole
flexboxgrid
raphael
rworldmap
myob
philips-hue
interrupt-handling
excel-2013
pptp
jboss5.x
crt
smart-mobile-studio
postgresql-9.2
body-parser
recurrence-relation
large-data
declare
freetts
haskell-pipes
ical-dotnet
google-account
median
apiary
fastq
onmouseover
double-buffering
taskmanager
drawingarea
defold
jags
ti-basic
text-classification
execl
in-memory-database
uicollectionviewlayout
gmt
spyne
update-site
wcf-ria-services
spark-cassandra-connector
dbscan
mpeg-4
multinomial
servlet-3.0
cctray
file-diffs
app.xaml
bridge
ember-cli-addons
ticket-system
hana-xs
colt
alertifyjs
android-looper
delphi-xe3
late-static-binding
svcutil.exe
gfs
loop-invariant
backbone-relational
nuspec
manage.py
sharpmap
qss
objcmongodb
dynamic-data
dropdownlistfor
usn
tfs-power-tools
deploying
windows-phone-7-emulator
z-machine
law-of-demeter
tcxgrid
pureftpd
chatroom
winverifytrust
longjmp

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App