Well I am at it again with my complex statements, I need some guidance on this one, in case you cannot tell I am a C++/C# programmer and not used to SQL, I think it is clear what I am trying to accomplish by what I have but ask if you need me to clarify: -
PROCEDURE [dbo].[spGetCIFSearch] (
-
@type int,
-
@max int,
-
@data varchar(25),
-
@flag int
-
)
-
AS
-
SET NOCOUNT ON
-
-
SELECT * INTO ##Temp FROM zCIFRecord AS C
-
WHERE InsertTime = (SELECT MAX(InsertTime) FROM zCIFRecord WHERE CIFPan = C.CIFPan)
-
AND CIFUpdateActivity NOT LIKE 'D'
-
-
BEGIN
-
IF @flag = 0
-
BEGIN
-
SELECT COUNT(*)
-
END
-
ELSE
-
BEGIN
-
SELECT (@max)
-
CIFPan,
-
CIFMemNum,
-
CIFLName,
-
CIFFName,
-
CIFInitial
-
END
-
-
FROM ##Temp
-
-
WHERE
-
CASE
-
WHEN @type = '1' THEN CIFFName LIKE @data
-
WHEN @type = '2' THEN CIFLName LIKE @data
-
WHEN @type = '3' THEN CIFFName+' '+CIFLName LIKE @data
-
WHEN @type = '4' THEN CIFPan LIKE @data
-
END
-
ORDER BY
-
CASE
-
WHEN @type = '1' THEN CIFFName DESC
-
WHEN @type = '2' OR '3' THEN CIFLName DESC
-
WHEN @type = '4' THEN CIFPan ASC
-
END
-
END
-
-
DROP TABLE ##Temp
-
Clearly I have several syntax errors, is it even possible to do what I want?
2 1554
Well I am at it again with my complex statements, I need some guidance on this one, in case you cannot tell I am a C++/C# programmer and not used to SQL, I think it is clear what I am trying to accomplish by what I have but ask if you need me to clarify: -
PROCEDURE [dbo].[spGetCIFSearch] (
-
@type int,
-
@max int,
-
@data varchar(25),
-
@flag int
-
)
-
AS
-
SET NOCOUNT ON
-
-
SELECT * INTO ##Temp FROM zCIFRecord AS C
-
WHERE InsertTime = (SELECT MAX(InsertTime) FROM zCIFRecord WHERE CIFPan = C.CIFPan)
-
AND CIFUpdateActivity NOT LIKE 'D'
-
-
BEGIN
-
IF @flag = 0
-
BEGIN
-
SELECT COUNT(*)
-
END
-
ELSE
-
BEGIN
-
SELECT (@max)
-
CIFPan,
-
CIFMemNum,
-
CIFLName,
-
CIFFName,
-
CIFInitial
-
END
-
-
FROM ##Temp
-
-
WHERE
-
CASE
-
WHEN @type = '1' THEN CIFFName LIKE @data
-
WHEN @type = '2' THEN CIFLName LIKE @data
-
WHEN @type = '3' THEN CIFFName+' '+CIFLName LIKE @data
-
WHEN @type = '4' THEN CIFPan LIKE @data
-
END
-
ORDER BY
-
CASE
-
WHEN @type = '1' THEN CIFFName DESC
-
WHEN @type = '2' OR '3' THEN CIFLName DESC
-
WHEN @type = '4' THEN CIFPan ASC
-
END
-
END
-
-
DROP TABLE ##Temp
-
Clearly I have several syntax errors, is it even possible to do what I want?
Possible? yes. Not that way.
Build your query dynamically like: - declare @strquery varchar(500)
-
-
set @strquery = 'select count(*) from .....'
-
-
exec (@strquuery)
-
-
-- CK
Thanks, that was a real "Duh" after I read your post. I was even going to title it dynamic query building! Thanks again.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: malcolm |
last post by:
Example, suppose you have these 2 tables
(NOTE: My example is totally different, but I'm simply trying to setup
the a simpler version, so excuse the bad design; not the point here)
CarsSold {...
|
by: Rodusa |
last post by:
I am trying to assign @sql variable to @total, where @sql is a sql
statement stored on the database, however what I am getting is its
string value and not its calcuation. Could anybody help?
...
|
by: 73blazer |
last post by:
Hello,
I'm looking for a SQL syntax to put a variable name into the from clause.
Specifically I have a colume in a table that is table name, and I want
to use that result in the from clause in a...
|
by: Greg Moll |
last post by:
I need to know the key strokes to insert fields into a select query.
I know how to use the mouse but I want to know the key stroke. Can
anyone help?
|
by: alex.kemsley |
last post by:
Hi guys,
I have the following sql statemant to search a mysql database that gets
if values from a form with combo box's in.
SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =...
|
by: FishVal |
last post by:
Hereby I'm proposing a way of convinient work with properties containing SQL Select statements, particulary RowSource property of ComboBox and ListBox.
The usual way is the following.
Private...
|
by: Thom Little |
last post by:
Using C# 3.5 I want to select a value from an XML file. The intent of the
following is to print "EpsilonGamma". It does not work. Can you point out
my probably very obvious error?
XmlDocument...
|
by: shapper |
last post by:
Hello,
I have the following LINQ:
List<Tagtags = (from t in
database.Tags
select t).ToList();
I need to restrict my results and for that I have two parameters:
StartWidth and N
|
by: paulmitchell507 |
last post by:
I think I am attempting a simple procedure but I just can't figure out
the correct syntax. My asp (classic) page runs a SELECT query to
obtain dates and ID's from 2 tables
uSQL = "SELECT...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |