473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQL Server Case Syntax

Hi fellow-developers,

I am literally hitting a wall trying to get the syntax right for this case statement.

Could someone please point out where I am going wrong?

Thanks in advance :)

DECLARE @cStr AS varchar(50)
DECLARE @nNum INT

SET @nNum = 0
SET @cStr = 'XX'
SET @nNum = (year(getdate()) - 2007)
print ' num P = ' + cast(@nNum as char)

SELECT CASE
WHEN (@nNum = 0) THEN SET @cStr = @cStr + 'CY'
WHEN (@nNum <> 0) THEN RAISERROR ('xxx', 16, 1)
WHEN (@nNum >= 10) THEN RAISERROR ('yyy.', 16, 1)
WHEN (@nNum < 10) THEN SET @cStr = @cStr + Replicate ('P', @nNum) + 'Y'
END
May 16 '07 #1
0 3648

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: wiredog | last post by:
I am struggling rewriting my query from MS Access' IIF, Then to SQL Servers TSQL language. I am hoping some one can give me some guidance. I believe I have the first portion of the query correct...
6
by: Andy Wawa | last post by:
Hi, on a simple HTML (not an ASP!)-Site I try to connect to a sql server (MS): <html> <title>Test</title> <head> <script language="javascript"> <!-- Function showForm(){
1
by: Ralph Krausse | last post by:
I know more html is needed to really produce this but enough is here for me to ask my question. So, this HTML code produce 2 buttons. One button is a HTML control and the other is ASP Web or Server...
15
by: Benny Raymond | last post by:
I'm confused as to how fallthrough is limited in switch. For example the following works: string switch_test = "a"; switch (switch_test) { case "a": case "b": case "c": doSomething(a);
7
by: chettiar | last post by:
Hi, I am trying to migrate SQL Server into DB2. In SQL Server there is code like: SET DATEFIRST 6 SELECT DATEPART(WEEK, '2006-01-31') What could be the equivalent DB2 code for this.
20
by: TC | last post by:
I need an automated procedure to copy data from an Access table to a SQL Server table. Speed is important. What is the recommended technique? I can export the data from Access, copy it via FTP,...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
11
by: dan-x | last post by:
I am a novice to SQL Server, so this is probably a really easy problem to fix. I'm translating an Oracle query and need to change the 'decode' to something compatible. Everything I've read points...
10
by: Anthony97 | last post by:
This is a problem I've been fighting through for the last month. I've been tasked with converting access 2007 queries to SQL Server 2005. I have been able to convert a number of queries associated...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.