November 21, 2004 at 11:06 pm
Hi,
In sql server we can have a select query like
Select [var1] = ‘Hello’,[var2] = t.col1
from table t
Now what is this [var1] or [var2] exactly? Can I use them as column names?
[Unitholder Social Code],
AccountNumber = ([Unitholder Account Number]+'-'+ [Unitholder Sub-Account Number]),
[From Date] = @FromDate ,
[To Date] = @ToDate ,
[Name] = case
WHEN @identifier = 'Client' THEN (select account_desc from dbo.refACCOUNT where account_id = @identifyingid )
WHEN @identifier = '
END,
[LoadCheckSum] =
case
WHEN @identifier= 'Client' THEN dbo.f_CalculateLoadChecksum (@identifyingid,NULL)
WHEN @identifier= '
END,
[RecCount] = dbo.f_getValidationReportCount(@identifyingid,@identifier,@FromDate,@ToDate),
[Identifier]= @identifier,
[IdentifierId] = @identifyingid,
Error1 =
case
WHEN cast([Fund Code] as varchar(10))=''
THEN 'Fund Code is not valid in UHR'+ char(13)
END +
case
WHEN ([Unitholder Social Code]is NULL OR LTRIM([Unitholder Social Code])= '' OR (dbo.ShareHolderTaxData.[Unitholder Social Code]<> dbo.ShareHolderTaxData.[Australian Tax Social Code]))
THEN 'The social codes are not the same'+ char(13)
end +
case
WHEN ([Unitholder Account Number]is NULL OR LTRIM([Unitholder Account Number])= '')
THEN 'The Unit holder account number is blank'+ char(13)
END +
case
WHEN ([Unitholder Sub-Account Number] is NULL OR LTRIM([Unitholder Sub-Account Number])= '')
THEN 'The Unit holder sub account number is blank '+ char(13)
END +
case
WHEN ([Unitholder Social Code]is NULL OR UPPER([Unitholder Social Code]) not in ('I','J','D','C','P','T','S','G','O') )
THEN 'The Investor Social Code is not D,C,P,T,S,G or O'+ char(13)
END
from dbo.ShareHolderTaxData
where [Fund Code] in (
select [UHR Fund Code] from refFMtoFundCode
where [Investment body Australian Business Number] = @identifyingid
and @identifier = '
and @identifier='Client')
)
and [Australian Tax Last Change Date CYMD] > = @FromDate
and [Australian Tax Last Change Date CYMD] < = @ToDate
and upper([Australian Tax Reportable]) = 'Y'
Supriya
November 22, 2004 at 3:44 am
Where did you get this from?
Select [var1] = ‘Hello’,[var2] = t.col1
from table t
I have never seen anything like that in SQL Server documents. The square brackets [] are used for column names that are 1) Reserved words or 2) have spaces in them.
Variables begin with the @ character. For example: @variable1.
So the example you used would actually be:
SELECT @var1 = 'Hello', @var2 = t.col1
FROM table t
-SQLBill
November 22, 2004 at 3:46 am
I should have added that you are better off doing:
SET @var1 = 'Hello'
SET @var2 = SELECT col1 FROM table
SELECT @var1, @var2
And don't forget to DECLARE the variables at the beginning.
-SQLBill
November 22, 2004 at 3:53 am
I have a constraint that i need to return a single resultset to crystal report so i can use only single select. The second select statement in the previous post is the actualy select where i am facing a problem.
There i actually need the rows for which Error1 != ''. Could you help me with that?
November 22, 2004 at 4:49 am
Okay, I hope I didn't get lost inside your queries, but to me it seems that you need to include the test for Error1 !='' in the WHERE clause. And if I see this right you need to repeat the expression there rather than just refer to the variable.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
November 22, 2004 at 5:18 am
Another thing to keep in mind is IF you are writing this inside Crystal Reports it will be a pain to maintain (know from experience). Why not write this as a stored-procedure that accepts parameters and have the datasource for the Crystal Report the EXEC sp?
This will make maintenance a lot easier and will avoid a lot of the nasties with Crystal when you start changing the source
Good Hunting!
AJ Ahrens
webmaster@kritter.net
November 22, 2004 at 5:23 am
i have actually written a stored proc which returns the resultset. The crystal report is able to access only one resultset from the stored proc too.
My problem here is the where cluase. Right now i have repeated the entire concatenation (the value of Error1) in the where clause. i am looking for a better approach.
Thanks for your responses
November 23, 2004 at 8:13 am
Would this do it?
SELECT * FROM (
-- Your whole select statement goes here
)
WHERE Error1 !=''
Bob Monahon
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply