How to use Assignment Operator in SQL Server - SQL Server / TSQL Tutorial Part 128

The equal ( = ) sign is used in TSQL as assignment operator. You will be using assignment operator many time when you write your TSQL Code.

1) Assign Value to Variable
Assignment Operator can be used to set the value for variable. You can simply assign static value to variable by using Assignment Operator or value returned by query.

Declare @i int
SET @i=2000
Print @i

Declare @Cnt int
SET @Cnt=(Select COUNT(*) from dbo.Customer)
Print @Cnt

Declare @CntRow int
Select @CntRow=Count(*) from dbo.Customer
Print @CntRow


2) Let's say you have dbo.Customer table and you want to add a static value column, You can use Assignment Operator to assign value to newly added column. In below example I am adding Region column by assigning 'North America'.


--Create Customer Table
Create table dbo.Customer
 (Id int,
  FName VARCHAR(50),
  LName VARCHAR(50),
  CountryShortName CHAR(2),
  Age tinyint)
GO
--Insert Rows in dbo.Customer Table
insert into dbo.Customer
Values (
1,'Raza','M','PK',10),
(2,'Rita','John','US',12),
(3,'Sukhi','Singh',Null,25),
(4,'James','Smith','CA',60),
(5,'Robert','Ladson','US',54),
(6,'Alice','John','US',87)



Also we can use the assignment operator for Alias. I have used CustomerID alias for ID column by using assignment operator.

Select 
CustomerId=Id,
FName,
LName,
CountryShortName,
Age,Region='North America' 
From dbo.Customer


What is Assignment Operator in SQL Server and How to use Assignment Operator - SQL Server / TSQL Tutorial


32 comments:

  1. The branch of accounting is a huge one, and there are mainly three types of offices in accounting. They are financial accounting, cost accounting and management accounting. Most people have a feeling that accounting is primarily a subject playing with numbers. Assignment Help London

    ReplyDelete
  2. I don't understand coding so I thought why not write my assignment a little differently.So I said to the teacher, I don't understand this coding assignment, so my teacher has to work on Business Management Dissertation, so my teacher gave me this assignment.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. BookMyEssay is one of the best writing agency, when it comes to providing Custom Coursework Writing Services with high quality work at an affordable cost.

    ReplyDelete
  5. Assignment operators in SQL Server can be a great help when it comes to professional essay writers for hire. With an assignment operator, you can easily insert data into your essay without having to retype it all. This can save you a lot of time and frustration.

    ReplyDelete
  6. This is a great article on the client reporting dashboard-venuearc in SQL Server. I didn't know that this was a thing, but it makes perfect sense. This will definitely help me with my event management.

    ReplyDelete
  7. As a college student who deals with this issue frequently, I completely agree with you. Even though you say that all students value their time, I completely understand how difficult it might be to submit a project on time through best assignment help service. The only way to finish a project on time is to use online assignment help.

    ReplyDelete
  8. If you want to use this coding language first learn it and use it very effectively with assignment or take my online class.

    ReplyDelete
  9. Thank you so much for sharing all this amazing info with great insights.
    Regards: Roofing Council Bluffs IA

    ReplyDelete
  10. Take professional expert help for BSBSTR601 Task 1 – Task 10 Templates and many more. Best Assignment services in Australia, globally trusted, instant Support, Plag free solution, 100% safe, order now!

    ReplyDelete
  11. The Faux leather and real leather are both used to make this Marlboro Leather Jacket. It has a silky, comfortable viscose lining to keep you at ease. An erect collar gives the wearer a fashionable appearance.

    ReplyDelete
  12. Unless individuals want to use this coding language, individuals must first learn it and use it effectively with assignments, or they can Pay someone to do my online class

    ReplyDelete
  13. There are primarily three different sorts of offices in the vast field of accounting. Accounting for finances, accounting for costs, and accounting for management. Do my online course

    ReplyDelete
  14. Using the Assignment operator in the SQL server was not a piece of cake for me, and my mind got stuck. Reading your post has reduced my tension, and I done my task easily. Thanks for helping us with informative content. Assignment Writing Help

    ReplyDelete
  15. For many students, writing an essay assignment is a challenging work that takes a long time to accomplish, but I have a solution. I'm a senior in college, and I normally prefer to have someone else Assignment Writing Service in uk

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Best PU Colleges in Mangalore
    Vibrant Moodubidire is widely recognized as the premier PU college in Mangalore, known for its exceptional academic programs and a vibrant learning atmosphere. It stands out as the top choice for students seeking a high-quality pre-university education in the region.

    ReplyDelete
  18. Learn the intricacies of the Assignment Operator in SQL Server with this insightful tutorial, Part 128 of the SQL Server/TSQL series. Mastering SQL fundamentals is pivotal for database management. Focus on genuine learning buy response essay to find the relevant experience of other users. Embrace educational resources to enhance your skills—empowering yourself for real-world applications in database management and SQL development.

    ReplyDelete
  19. I had a complex assignment that I was struggling with. Philosophy Dissertation Topics by Native Assignment help came to my rescue. The expert assigned to my task demonstrated profound knowledge of the subject and delivered a flawless paper. The best part was the insightful explanations provided, which helped me grasp the concepts better.

    ReplyDelete
  20. Explore a myriad of engaging and thought-provoking Geography Dissertation Ideas to elevate your academic journey. Uncover innovative topics that delve into
    the dynamic realms of human geography, physical geography, and GIS, ensuring your dissertation stands out as a testament to your scholarly prowess.

    ReplyDelete
  21. Embark on your academic journey with a rich selection of Criminology Dissertation Ideas designed to inspire original research and contribute to the evolving discourse within the field. From analyzing the sociological underpinnings of crime to investigating the effectiveness of rehabilitation programs, our comprehensive list ensures you find a compelling and intellectually stimulating topic for your dissertation.

    ReplyDelete
  22. Make the journey to dissertation completion smoother by delegating the task with the phrase, Write My Dissertation . Our committed team of writers is prepared to handle the intricacies of research, analysis, and writing, ensuring your dissertation not only meets but surpasses the stringent academic requirements. Say goodbye to stress and hello to a professionally written and impactful dissertation.



    ReplyDelete

  23. In this SQL Server tutorial, the assignment operator (=) is demonstrated for various tasks like setting variable values, adding static values to columns, and creating aliases. The examples cover basic operations in TSQL, showcasing its versatility in assigning values efficiently.
    Looking for assignment help in the UK? Our online assignment company offers top-notch Assignment Help in UK. From essays to research papers, our team of experts is here to provide you with high-quality assignments that meet your requirements and deadlines. Whether you're struggling with a particular subject or need help refining your writing skills, we've got you covered. With our Assignment Helper, you can expect timely delivery and professional support every step of the way. Get in touch with us today to elevate your academic performance.

    ReplyDelete
  24. Dr. Maetreyii Ma - Yoga Ma Said!
    This T-SQL guide offers a concise yet comprehensive overview of the assignment operator's versatility in various SQL scenarios. It provides clear examples, making complex concepts easily understandable. Great job on breaking down the topic into digestible pieces!

    ReplyDelete
  25. Marketing assignment help and assignment helper services offer students expert assistance in completing their marketing assignments effectively. These services provide professional guidance, resources, and support to ensure students understand marketing concepts, develop their skills, and achieve academic success. By accessing these services, students can improve their grades and overall understanding of marketing principles.

    ReplyDelete
  26. Offering guidance and support, Assessment Help ensures students understand their coursework, prepare effectively for exams, and achieve academic success. This assistance can come in various forms, such as tutoring, study materials, practice tests, and personalized feedback on assignments. By addressing individual learning needs and identifying areas for improvement, assessment help enables students to build confidence and develop essential skills. It also promotes a deeper understanding of subject matter, encourages critical thinking, and fosters a proactive approach to learning. Whether through one-on-one sessions, group workshops, or online resources, assessment help plays a crucial role in enhancing educational outcomes and empowering students to reach their full potential.

    ReplyDelete
  27. For Assignment help London seeking academic support, professional assignment help services are available to ensure success. These services offer expert guidance, customized solutions, and thorough research to help you excel in your nursing studies. Achieve academic excellence with reliable nursing assignment help in London.

    ReplyDelete
  28. The pressures of nursing school can be overwhelming, and the added stress of capella 4900 assessment 1 meeting BSN Writing Services academic deadlines can affect students' mental and emotional well-being. By utilizing writing services, students can alleviate some of this pressure, allowing them to focus more on their clinical training and personal well-being. This balance is crucial for maintaining a healthy academic and personal life.

    ReplyDelete
  29. Assignment help and essay writing services ukprovide students with valuable support in managing their academic workload. These services offer professional assistance in crafting well-researched, high-quality essays, reports, and other academic assignments. Students benefit from expert guidance, timely delivery, and tailored content that meets specific requirements. Whether struggling with time management, complex topics, or language barriers, students can rely on these services to enhance their academic performance. Additionally, these platforms often provide plagiarism-free content and allow for revisions, ensuring that the final product aligns with the student’s expectations and academic standards.

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. Struggling with your project management assignment? Our expert team is here to provide top-notch assistance! We offer personalized support to help you understand project planning, execution, and control. Whether it's a detailed report or a complex case study, we ensure high-quality, plagiarism-free work is delivered on time. For reliable help with your project management assignments, visit here for project management assignment help and get the expert support you need.

    ReplyDelete
  32. University assignment help at My Assignment Help is a fantastic resource for students who need expert guidance on their coursework. Whether you're struggling with a difficult topic, facing tight deadlines, or just looking for high-quality support to boost your grades, My Assignment Help provides personalized assistance across a wide range of subjects. Their team of professional writers ensures that each assignment is thoroughly researched, well-structured, and tailored to meet the academic requirements of your university. With this service, you can improve your understanding of complex concepts while submitting polished, original work.

    ReplyDelete