Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am not sure how does it called, so I am not sure how to search for my need.

My MS SQL query:

UPDATE temp 
SET temp.x = (SELECT CONVERT(DATE, right(right('0' 
 + cast((select s.col1 from table1  s where temp.id=s.id) as nvarchar(8)), 8), 4)
 + left(right('0' 
 + cast((select s.col1 from table1  s where temp.id=s.id) as nvarchar(8)), 8), 4)) 
)

I want to define a variable for this subquery select s.col1 from table1 s where temp.id=s.id. Something like SET mysubquery ofquerytype= select s.col1 from table1 s where temp.id=s.id. Then I could reuse the mysubquery.

share|improve this question

closed as off-topic by Phrancis, Jamal Feb 8 at 4:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Phrancis, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.

    
The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. – Jamal Feb 8 at 2:56
    
This will likely be off-topic as you are asking about changing what the code does. What you are looking for is likely stored procedures, look it up on MSDN. – Phrancis Feb 8 at 4:34

Browse other questions tagged or ask your own question.