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

TFS SQL - Select a list of unmerged changesets
How to write SSRS report that compares end of month values?
SQL Server, first of each time series
Connection Waiting For SQL Remote Connection Freeze My App
Using BCP and xp_cmdshell with T-SQL inside SSMS. “The syntax of the command is incorrect”
SQL Server triggers to check credit card balance
How to use stored procedure to calculate DateTime difference in hours?
Loop through table by row T-SQL
Audit Microsoft SQL Server table with many columns
Select joining table based on condition
Linked server with same server name
How to group by two dates to sum an quantity
Retrieving record to a combo box in vb.net
Need select 2 rows from Table2, which is joined with Table1. See description
Can't add a connection in Visual Studio: no server name available
Average of a date column in sql [duplicate]

Categories

HOME
sql-server
rest
ajax
caching
sas
plsql
paramiko
apache2
filter
dataframe
jpanel
structuremap
xul
abcpdf
data-analysis
rapidjson
grub2
off-canvas-menu
saiku
google-openid
atlassian-plugin-sdk
ip-camera
google-ima
countif
ghost-inspector
explode
sumo
data-conversion
getjson
apache-cloudstack
clockwork
pyscripter
google-drive-realtime-api
npm-shrinkwrap
rhino
powershell-remoting
broadleaf-commerce
sql-like
jquery-multidatespicker
alchemy.js
socketscan
onbackpressed
react-native-router-flux
windows-firewall
gauss
gist
seamless-immutable
decompress
mercury
date-range
sqlexception
master
alter
glkit
galleriffic
wcf-ria-services
visible
radians
foxit
amf
pagekit
fps
picking
asp.net-mvc-2
altbeacon
cctray
affix
zuora
apigee-baas
ubercart
crash-dumps
mdm-zinc
sysfs
orientation-changes
candidate-key
jquery-autocomplete
collabnet
csplit
aquafold
crystal-reports-10
gfs
osx-snow-leopard
sql-server-2012-web
justgage
apache2.2
dwolla
soa-suite
xml-libxml
gdataxml
dropdownlistfor
returnurl
cadisplaylink
pstree
die
signals2
nintendo
v4l
nsindexpath
zookeeper
goliath
adobe-contribute
audiostreamer
front-controller
web-statistics
callgrind
act
hmacsha1
database-diagramming
ajaxpro
writing

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