CASE Statement Throwing Exception

Feb 26, 2008

I am using Compact Edition 3.5 against the Northwind.sdf database. The following SQL statement throws an error window in Visual Studio 2008 that states "The parameter is incorrect.". This only occurs when I have an input parameter inside the CASE statement.

**********************************************************************************************************
PLEASE DO NOT TELL ME I CAN JUST USE 'WHERE @CompanyName LIKE '%ABB%''
BECAUSE I UNDERSTAND THAT - I WANT TO KNOW WHY THE SYNTAX I HAVE IS
THROWING AN EXCEPTION
**********************************************************************************************************


This throws an exception when input parameter is in the CASE statement:
SELECT [Customer ID]
FROM Customers
WHERE (CASE WHEN @CompanyName LIKE '%ABB%' THEN 1 ELSE 0 END = 1)


This DOES NOT throw an exception (I know they do not get me the same results):

SELECT [Customer ID]
FROM Customers
WHERE (CASE WHEN [Company Name] LIKE '%ABB%' THEN 1 ELSE 0 END = 1)


TIA!

View 6 Replies


ADVERTISEMENT

RAISEERROR Not Throwing Exception In .NET

Jul 9, 2007

I am calling a stored procedure that looks like this.


Code:


ALTER PROCEDURE [dbo].[VerifyLogin]
-- Add the parameters for the stored procedure here
@Email nvarchar (100),
@Password nvarchar (200)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @Count int
DECLARE @Accounts int

SET @Accounts = (Select Count(*) from Users Where UPPER(Email) = UPPER(@Email))

IF @Accounts = 0
BEGIN
RAISERROR('E-mail address not found.', 10, 1)
END
ELSE
BEGIN
SET @Count = (Select Count(*) from Users Where UPPER(Email) = UPPER(@Email) and Password = @Password)

IF @Count > 0
select 1 as Verification
ELSE
select 0 as Verification
END
END



When I enter a login that does not exist, the error is not thrown in .net. Tracing the code shows normal execution. What am I doing wrong?

View 1 Replies View Related

' Question Throwing Exception

Aug 24, 2006

I have a comboBox with some names binded to it....With in the names some of them are like--- Store's Store, and like Danny's Gym...when i select names with ' in them i get this exception

Incorrect Syntax near 'S' Unclosed Question mark before the charectar string ORDER BY "SomeValue".....how could i go about fixing this?????

 

should i include some king of function that pulls out those quotes??? or what??? any help with this issue

 

 

View 3 Replies View Related

Custom Report Renderer Throwing An Exception

Jan 31, 2008

I have to create a custom rendering extension for SQL Server 2005 Reporting Services.

I followed the instructions in the MSDN article: http://msdn.microsoft.com/msdnmag/issues/05/02/CustomRenderers/default.aspx

I am running the report server under an administrative account provileges on the local machine (XP Pro SP2).
The Reporting Services is installed for SQL Server 2005 Trial/Evaluation Edition (not expired yet) and has been upgraded to Service Pack 2.
The Report Manager runs under a default ASPNET account.

After deploying the extension according to instructions in the article, I see the custom renderer in the list of available rendering formats in the dropdown in the Report Manager.

However, when I select that renderer and click "Export", a new IE window opens with the following error message:


Server Error in '/Reports$SQLSERVER2005DEV' Application.


That assembly does not allow partially trusted callers.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: That assembly does not allow partially trusted callers.

Source Error:





An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:





[Exception: That assembly does not allow partially trusted callers.]

[Exception: An error occurred during rendering of the report.]

[Exception: An unexpected error occurred in Report Processing.]
Microsoft.Reporting.WebForms.ServerReport.ServerUrlRequest(Boolean isAbortable, String url, Stream outputStream, String& mimeType, String& fileNameExtension) +503
Microsoft.Reporting.WebForms.ServerReport.InternalRender(Boolean isAbortable, String format, String deviceInfo, NameValueCollection urlAccessParameters, Stream reportStream, String& mimeType, String& fileNameExtension) +958
Microsoft.Reporting.WebForms.ServerReportControlSource.RenderReport(String format, String deviceInfo, NameValueCollection additionalParams, String& mimeType, String& fileExtension) +84
Microsoft.Reporting.WebForms.ExportOperation.PerformOperation(NameValueCollection urlQuery, HttpResponse response) +143
Microsoft.Reporting.WebForms.HttpHandler.ProcessRequest(HttpContext context) +153
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64




Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433


My "why is it not working" question basically breaks down to 3 questions:

1. Why does this error say "partially trusted" whereas the new element in the rssrvpolicy.config file explicitly asks for "FullTrust" permissions?

2. Is there any deployment step that I'm missing?
[For now, it's:
- copy-and-paste the dll into ReportServerin directory;
- add a new CodeGroup element to the rssrvpolicy.config file;
- add a new Extension element to the rsreportserver.config file;
- IIS reset;
- Reporting Services service restart.]

3. Also, I checked the deployment instructions in BOL (Deploying Rendering Extension: http://msdn2.microsoft.com/en-us/library/ms154516.aspx), just to make sure I didn't miss anything.
An interesting this is, the BOL article does NOT mention a requirement for adding a new element into rssrvpolicy.config file.
Is this an error in the September 2007 Books Online?


The same error (regarding "partically trusted" - see above) occurs even after I signed the assembly with a strong name key (although this is not mentioned in the articles, but I figured it might be necessary).

Could someone point me in the right direction as to how to properly deploy a custom rendering extension, please?

Thanks a lot!

View 3 Replies View Related

Subreport Throwing An Exception When Placed In A Group Footer

Jul 24, 2006

I ran into this a few weeks ago and found that several others had as well, but no one had yet found an answer. I found the answer (at least one of the answers) this weekend and wanted to share it. I had recently added a subreport to a group footer in a table and started getting an error. Depending on the data, the error wasn't always present. I didn't have a problem when I moved the subreport to any other area in the report.

Here is the error I was getting:

An error occurred during local report processing

An internal error occurred on the report server. See the error log for more details.

It was a local report (rdlc), so naturally, there was no error log <g>. I added an event handler for ReportError and collected this information:

7/23/2006 5:18:22 PM
OS: Microsoft Windows NT 5.1.2600 Service Pack 2

*** EXCEPTION ***
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
Stack Trace: at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at SX.MainProgram.Main() in C:Documents and SettingsMYeagerMy DocumentsVisual Studio 2005ProjectsSXSXMainProgram.cs:line 22


*** INNER EXCEPTION ***
Message: Reporting Service Exception
Source: SX
Stack Trace: at SX.ReportSalesForm.reportViewer1_ReportError(Object sender, ReportErrorEventArgs e) in C:Documents and SettingsMYeagerMy DocumentsVisual Studio 2005ProjectsSXSXReportFormsReportSalesForm.cs:line 84
at Microsoft.Reporting.WinForms.ReportViewer.OnError(Exception e)
at Microsoft.Reporting.WinForms.ReportViewer.UpdateUIState(Exception e)
at Microsoft.Reporting.WinForms.ReportViewer.OnRenderingCompleteUI(ProcessThreadResult result, PostRenderArgs postRenderArgs)


*** INNER EXCEPTION ***
Message: An error occurred during local report processing.
Source: Microsoft.ReportViewer.WinForms
Stack Trace: at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Microsoft.Reporting.WinForms.ProcessingThread.ProcessThreadMain(Object arg)


*** INNER EXCEPTION ***
Message: An internal error occurred on the report server. See the error log for more details.
Source: Microsoft.ReportViewer.Common
Stack Trace: at Microsoft.ReportingServices.Diagnostics.Utilities.RSTraceInternal.Assert(Boolean condition, String componentName)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteVariant(Object variant, Boolean convertDBNull)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteScopeTableValues(Object value)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteScopeTableValues(Object value)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteScopeLookupTable(ScopeLookupTable scopeTable)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteSubReport(SubReport subReport)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItem(ReportItem reportItem)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItemList(ReportItemList reportItems)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItemCollection(ReportItemCollection reportItems)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteRectangle(Rectangle rectangle)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItem(ReportItem reportItem)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItemList(ReportItemList reportItems)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItemCollection(ReportItemCollection reportItems)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteTableRow(TableRow tableRow)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteTableRowList(TableRowList rows)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteTableGroup(TableGroup tableGroup)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteTable(Table table)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteDataRegion(DataRegion dataRegion)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItem(ReportItem reportItem)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItemList(ReportItemList reportItems)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportItemCollection(ReportItemCollection reportItems)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReport(Report report)
at Microsoft.ReportingServices.ReportProcessing.Persistence.IntermediateFormatWriter.WriteReportSnapshot(ReportSnapshot reportSnapshot)
at Microsoft.ReportingServices.ReportProcessing.ChunkManager.SnapshotChunkManager.SaveReportSnapshot(ReportSnapshot reportSnapshot)
at Microsoft.ReportingServices.ReportProcessing.ProcessingResult.Save()
at Microsoft.Reporting.LocalService.Render(PreviewItemContext itemContext, Boolean allowInternalRenderers, ParameterInfoCollection reportParameters, IEnumerable dataSources, DatasourceCredentialsCollection credentials, CreateAndRegisterStream createStreamCallback, ReportRuntimeSetup runtimeSetup, ProcessingMessageList& warnings)
at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)


This wasn't exactly enlightening, an exception in an ASSERT in the reporting services dll, but since I knew that results varied with different data, I tracked it down that way.

THE SOLUTION:

The problem occurs when data for group expression is null. If there is no subreport in the group footer, this isn't an issue, but if there is, you get the error. For instance, if your data comes from a SQL statement with a LEFT OUTER JOIN (as mine did), and the group expression uses a column that contains nulls as a result of the LEFT OUTER, this exception will be thrown. This one was VERY DIFFICULT to track down, but it's easily reproducable. It has nothing to do with what (if anything is) on the subreport, what the data the subreport uses looks like, whether there are parameters or not. It's purely having nulls in the data used by the group expression for the main report. I found that if I changed my SELECT from mytable.mycolumn to ISNULL(mytable.mycolumn, 0) the error went away.

Mike Yeager

View 5 Replies View Related

Throwing Exception In Stored Proc To Catch In C# And Rollback The Transaction

Sep 27, 2007




Hi,

I am using sql2k5. I just wanted to throw an error from stored procedure with some message to C# to rollback my transaction.
Here is how i wnated to do ( in sequence )

C#
=====
Open a connection
Begin the transaction
Execute the command

In the Stored Proc
===========
do multiple operations one by one
if error
stop processing further
Throw the error
C#
========
if exception
rollback the transaction
else
commit the transaction

I have tried using raise error in stored proc but never thrown exception

Can any one let me know how to achieve this scenario??

~Mohan Babu

View 5 Replies View Related

Simple DB Operations Are Throwing Native Exception Error - 0xc0000005 - Intermittently

Dec 4, 2006

Hi All,

We have written a multithreaded application in which we are maintaining separate Database connections for each thread. these connections are opened and closed at the start and exit of the thread.

We have observed that even if there is only one thread running ( application thread), execution of simple Select queries some times throws Native exception(Error - 0xc0000005 ).

This error comes intermittently. Execution of same query doesn't throw exception.

Further investigation by breaking the debug at the time of native exception and then looking into the stack trace shows that native exception has occured at one of the Native API (CompileQueryPlan() ) which is being called implicitly by the SQL Mobile.

Each time when we see native exception stack trace shows failure at CompileQueryPlan() call.

Let me know if this is a known defect in SQL Mobile 2005 or there is something else that is causing native exception.

Thanks,

Nikhil











View 11 Replies View Related

Problem Using Result From CASE In Another CASE Statement

Nov 5, 2007

I have a view where I'm using a series of conditions within a CASE statement to determine a numeric shipment status for a given row. In addition, I need to bring back the corresponding status text for that shipment status code.

Previously, I had been duplicating the CASE logic for both columns, like so:




Code Block...beginning of SQL view...
shipment_status =
CASE
[logic for condition 1]
THEN 1
WHEN [logic for condition 2]
THEN 2
WHEN [logic for condition 3]
THEN 3
WHEN [logic for condition 4]
THEN 4
ELSE 0
END,
shipment_status_text =
CASE
[logic for condition 1]
THEN 'Condition 1 text'
WHEN [logic for condition 2]
THEN 'Condition 2 text'
WHEN [logic for condition 3]
THEN 'Condition 3 text'
WHEN [logic for condition 4]
THEN 'Condition 4 text'
ELSE 'Error'
END,
...remainder of SQL view...






This works, but the logic for each of the case conditions is rather long. I'd like to move away from this for easier code management, plus I imagine that this isn't the best performance-wise.

This is what I'd like to do:



Code Block
...beginning of SQL view...
shipment_status =
CASE
[logic for condition 1]
THEN 1
WHEN [logic for condition 2]
THEN 2
WHEN [logic for condition 3]
THEN 3
WHEN [logic for condition 4]
THEN 4
ELSE 0
END,


shipment_status_text =

CASE shipment_status

WHEN 1 THEN 'Condition 1 text'

WHEN 2 THEN 'Condition 2 text'

WHEN 3 THEN 'Condition 3 text'

WHEN 4 THEN 'Condition 4 text'

ELSE 'Error'

END,
...remainder of SQL view...


This runs as a query, however all of the rows now should "Error" as the value for shipment_status_text.

Is what I'm trying to do even currently possible in T-SQL? If not, do you have any other suggestions for how I can accomplish the same result?

Thanks,

Jason

View 1 Replies View Related

CASE Throws Conversion Failed When Converting Datetime From Character String Exception

May 1, 2008



Hi All,

I have SQL query as:


SELECT CASE @sortcolumn

WHEN 'TYPE' THEN TYPE_TXT

WHEN 'DATE' THEN CHECKOUT_TS

WHEN 'ACCT' THEN ACCT_NBR

WHEN 'FIRST' THEN FIRST_NM

WHEN 'LAST' THEN LAST_NM

WHEN 'DAYS' THEN DATEDIFF(dd, CHECKOUT_TS, GETDATE())

ELSE DELIVER_ID END

FROM REQUEST

If @sortcolumn has 'DATE' or 'DAYS' it runs fine....any other value, I get an exception "Conversion failed when converting datetime from character string". All columns except CHECKOUT_TS are of type varchar.

Any help would be greatly appreciated.

Thanks,
Shashi

View 3 Replies View Related

SQL Server 2012 :: Update Statement With CASE Statement?

Aug 13, 2014

i was tasked to created an UPDATE statement for 6 tables , i would like to update 4 columns within the 6 tables , they all contains the same column names. the table gets its information from the source table, however the data that is transferd to the 6 tables are sometimes incorrect , i need to write a UPDATE statement that will automatically correct the data. the Update statement should also contact a where clause

the columns are [No] , [Salesperson Code], [Country Code] and [Country Name]

i was thinking of doing

Update [tablename]
SET [No] =
CASE
WHEN [No] ='AF01' THEN 'Country Code' = 'ZA7' AND 'Country Name' = 'South Africa'
ELSE 'Null'
END

What is the best way to script this

View 1 Replies View Related

How To Write Select Statement Inside CASE Statement ?

Jul 4, 2006

Hello friends,
I want to use select statement in a CASE inside procedure.
can I do it? of yes then how can i do it ?

following part of the procedure clears my requirement.

SELECT E.EmployeeID,
CASE E.EmployeeType
WHEN 1 THEN
select * from Tbl1
WHEN 2 THEN
select * from Tbl2
WHEN 3 THEN
select * from Tbl3
END
FROM EMPLOYEE E

can any one help me in this?
please give me a sample query.

Thanks and Regards,
Kiran Suthar

View 7 Replies View Related

Transact SQL :: Update Statement In Select Case Statement

May 5, 2015

I am attempting to run update statements within a SELECT CASE statement.

Select case x.field
WHEN 'XXX' THEN
  UPDATE TABLE1
   SET TABLE1.FIELD2 = 1
  ELSE
   UPDATE TABLE2
   SET TABLE2.FIELD1 = 2
END
FROM OuterTable x

I get incorrect syntax near the keyword 'update'.

View 7 Replies View Related

Case Statement Error In An Insert Statement

May 26, 2006

Hi All,
I've looked through the forum hoping I'm not the only one with this issue but alas, I have found nothing so I'm hoping someone out there will give me some assistance.
My problem is the case statement in my Insert Statement. My overall goal is to insert records from one table to another. But I need to be able to assign a specific value to the incoming data and thought the case statement would be the best way of doing it. I must be doing something wrong but I can't seem to see it.

Here is my code:
Insert into myTblA
(TblA_ID,
mycasefield =
case
when mycasefield = 1 then 99861
when mycasefield = 2 then 99862
when mycasefield = 3 then 99863
when mycasefield = 4 then 99864
when mycasefield = 5 then 99865
when mycasefield = 6 then 99866
when mycasefield = 7 then 99867
when mycasefield = 8 then 99868
when mycasefield = 9 then 99855
when mycasefield = 10 then 99839
end,
alt_min,
alt_max,
longitude,
latitude
(
Select MTB.LocationID
MTB.model_ID
MTB.elevation, --alt min
null, --alt max
MTB.longitude, --longitude
MTB.latitude --latitude
from MyTblB MTB
);

The error I'm getting is:
Incorrect syntax near '='.

I have tried various versions of the case statement based on examples I have found but nothing works.
I would greatly appreciate any assistance with this one. I've been smacking my head against the wall for awhile trying to find a solution.

View 10 Replies View Related

How To Show Records Using Sql Case Statement Or If Else Statement

Feb 20, 2008

i want to display records as per if else condition in ms sql query,for this i have used tables ,queries as follows


as per data in MS Sql

my tables are as follows
1)material
fields are -- material_id,project_type,project_id,qty, --

2)AB_Corporate_project
fields are-- ab_crp_id,custname,contract_no,field_no

3)Other_project
fields are -- other_proj_id,other_custname,po

for ex :
vales in table's are
AB_Corporate_project
=====================
ab_crp_id custname contract_no field_no
1 abc 234 66
2 xyz 33 20

Other_project
============
other_proj_id other_custname po
1 xxcx 111
2 dsd 222

material
=========
material_id project_type project_id qty
1 AB Corporate 1 3
2 Other Project 2 7

i have taken AB Corporate for AB_Corporate_project ,Other Project for Other_project


sample query i write :--

select m.material_id ,m.project_type,m.project_id,m.qty,ab.ab_crp_id,
ab.custname ,op.other_proj_id,op.other_custname,op. po
case if m.project_type = 'AB Corporate' then
select * from AB_Corporate_project where ab.ab_crp_id = m.project_id
else if m.project_type = 'Other Project' then
select * from Other_project where op.other_proj_id=m.project_id
end
from material m,AB_Corporate_project ab,Other_project op


but this query not work,also it gives errors

i want sql query to show data as follows


material_id project_type project_id custname other_custname qty
1 AB Corporate 1 abc -- 3
2 Other Project 2 -- dsd 7

so plz help me how can i write sql query for to show the output
plz send a sql query

View 8 Replies View Related

Sqljdbc Exception While Execute Batch Statement (Seems BUG)

Mar 17, 2008

The following exception is thrown with sqljdbc.jar (not with jtds0.9.jar)

com.microsoft.sqlserver.jdbc.SQLServerException: New request is not allowed to start because it should come with valid transaction descriptor.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$1ConnectionCommand.doExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectionCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.rollback(Unknown Source)
at org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:265)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:288)


While using the query :


if not exists ( select 1 from sysindexes where id = object_id('aaa') and name = 'aaa_pk')create unique nonclustered index aaa_pkon aaa(id)using Statement.executeBatch()at conection.commit()

Sample Code

conn = getConnection();

// create the statement and execute the query
Statement stmt = null;
try
{
conn.setAutoCommit(false);
stmt = conn.createStatement();
for ( String sql : sqlList )
{
stmt.addBatch( sql );
}

results = stmt.executeBatch();
stmt.clearBatch();
conn.commit(); //throws the exception
}
catch ( SQLException e )
{
try
{
conn.rollback();
}
catch ( SQLException e1 )
{
throw new DataSourceException( e1 );
}
throw new DataSourceException( "Error executing sql: %1", e, sqlList.toString() );
}

View 1 Replies View Related

'((System.Exception)($exception)).Message' Threw An Exception Of Type 'System.NotSupportedException'

Jan 16, 2008

Greetings everyone, I am attempting to build my first application using Microsofts Sql databases. It is a Windows Mobile application so I am using Sql Server Compact 3.5 with Visual Studio 2008 Beta 2. When I try and insert a new row into one of my tables, the app throws the error message shown in the title of this topic.
'((System.Exception)($exception)).Message' threw an exception of type 'System.NotSupportedException'



My table has 4 columns (i have since changed my FavoriteAccount datatype from bit to Integer)
http://i85.photobucket.com/albums/k71/Scionwest/table.jpg

Account type will either be "Checking" or "Savings" when a new row is added, the user will select what they want from a combo box.

Next is a snap shot of my startup form.
http://i85.photobucket.com/albums/k71/Scionwest/form.jpg



Where it says "Favorite Account: None" in the top panel, I am using a link label. When a user clicks "None" it will go to a account creation wizard, and set the first account as it's primary/favorite. As more accounts are added the user can select which will be his/her primary/favorite. For now I am just creating a sample account when the label is clicked in an attempt to get something working. Below is the code used.


private void lnkFavoriteAccount_Click(object sender, EventArgs e)

{

FinancesDataSet.BankAccountRow account = this.financesDataSet.BankAccount.NewBankAccountRow();

account.Name = "MyBank Checking Account";

account.AccountType = "Checking";

account.Balance = Convert.ToDecimal("15.03");

account.FavoriteAccount = 1;//datatype is an integer, I have changed it since I took the screenshot.

financesDataSet.BankAccount.Rows.Add(account);
//The next three lines where added while I was trying to get this to work.
//I don't know if I really need them or not, I receive the error regardless if these are here or not.



this.bankAccountTableAdapter1.Update(financesDataSet);

this.financesDataSet.AcceptChanges();

refreshDatabase();

}


the refreshDatabase() code is here:


private void refreshDatabase()

{

this.bankAccountTableAdapter1.Fill(this.financesDataSet.BankAccount);

//Aquire a count of accounts the user has

int numAccounts = financesDataSet.BankAccount.Count;

//Loop through each account and see which one is the primary.

for (int num = 0; num != numAccounts; num++)

{
//Works ok in frmMain_Load, but when my lnkFavoriteAccount_click calls this, it throws the error.

if (this.financesDataSet.BankAccount[num].FavoriteAccount == 1)

{
//Display the primary account on our home page. User can click the link label & be taken to their account register.

this.lnkFavoriteAccount.Text = this.financesDataSet.BankAccount[num].Name.ToString();

this.lnkFavoriteFunds.Text = this.financesDataSet.BankAccount[num].Balance.ToString();

break;

}

}

}


and my form_load code

private void frmMain_Load(object sender, EventArgs e)

{

refreshDatabase();

}


So, when I click on the lnkFavoriteAccount label, and my new row gets added, the app stops at the following line in my DataSet.Designer

[global:ystem.Diagnostics.DebuggerNonUserCodeAttribute()]

public byte FavoriteAccount {

get {

try {

return ((byte)(this[this.tableBankAccount.FavoriteAccountColumn]));

}

catch (global:ystem.InvalidCastException e) {
//Stops at the following line, this error was caused by 'if (this.financesDataSet.BankAccount[num].FavoriteAccount == 1)'

throw new global:ystem.Data.StrongTypingException("The value for column 'FavoriteAccount' in table 'BankAccount' is DBNull.", e);

}

}

set {

this[this.tableBankAccount.FavoriteAccountColumn] = value;

}

}


I have no idea what I am doing wrong, all of the code I used I retreived from Microsofts help documentation included with VS2008. I have tried used my TableAdapter.Insert() method and it still failed when it got to

if (this.financesDataSet.BankAccount[num].FavoriteAccount == 1)

in my refreshDatabase() method it still failed.

When I look, the data has been added into the database, it's just when I try to retreive it now, it bails on me. Am I retreiving the information wrong?

Thanks for any help you guys can offer.

Johnathon

View 1 Replies View Related

Case Statement In Sql Help

Jan 18, 2008

I am trying to use a case statement in one of my stored proc but I am stuck a little bit.Here is a example, something like:declare @id int   set @id =1case @id         When 1 then select  *  from contactsend case but this keeps on giving me error: Incorrect syntax near the keyword 'case'. Any help is appreciated! 

View 7 Replies View Related

Case Statement

Apr 22, 2008

Hi I have some question regarding the sql case statment.Can i use the case statement with the where clause.Example: SELECT FirstName, IDFROM myTablewhere case when ID= '123' then id = '123' and id='124' endorder by idBut the above code does not work.  

View 9 Replies View Related

Sql Case Statement Help

Jun 2, 2005

Hi all,
I was wondering if there is any way in an sql statement to check whether the data your trying to get out of the DB is of a particular type, ie. Int, char etc. I was thinking about a case statement such as
<code>
CASE WHEN (MyNum <> INT) then 0 end AS MyNum
</code>
 
This has to be included in the sql statement cause I need this field to get other data.
Any thoughts on how to achieve this would be greatly appreciated.
 
If I’m in the wrong thread section please advise of best one to get help in.

View 1 Replies View Related

What Is The Best SQL Statement For This Case ?

Sep 17, 2005

Hi !!!i hope one of the sql specialists answer me about the best and most effeceint way to acheive what i am looking for Scenario:-------------i have a 3 tables related to each other Addresses, Groups and GroupAddressthe relation is for both addresses and groups  is one to many in the GroupAddress.the behaviour in the application : user can add addresses to his address list and from the address list a user can add an address to many groups like if you have Group name "Freinds" and you add me in it and you have Football team group and you add me to it like that !!!not i have another function called "copy group"in the GroupAddress i have this data as example GroupID   AddressID1                41                61                21              441              72              82             62             93            133             73           10and the group ID called "Freinds"i want to copy the group so i can have another group that has the same addresses by one click rather than collectiong them again one by one ...by the way the new copy will have a new group name ( as this is thebusiness logic so user can not have dupicate group name )so what is the best SQL statement that i need to copy the group ???i hope that clear enough!

View 2 Replies View Related

CASE Statement

Jan 23, 2002

I am trying determine if I can do something like the code below. I have done a left join on a table. In the select statement there are three possible values. Yes, No, or NULL. I could like to use a Case statement to determine if there is Null. If so, then output N/A in place of the Null. So then my possible valus are Yes, No, and N/A.

Any clues?

Thanks,
John

SELECT TOP 100
OfferDressRoomYN.yesno as OfferDressRoom
= CASE
WHEN offerDressRoomYN.yesno IS NULL THEN 'N/A'
END,
FROM dataquestionnaire dq
LEFT OUTER JOIN yesno OfferDressRoomYN ON dq.c3_1 = OfferDressRoomYN.yesnoid

View 2 Replies View Related

Case Statement

Aug 27, 2001

Hi
Can anybody tell me how to execute store procedure in the case statement.

Thanks

View 1 Replies View Related

Case Statement

Sep 23, 2002

How do l use the case statement to cater for these updates.


BEGIN TRANSACTION
UPDATE TBL_DEV_OL_NEW1
SET Entity = ('AB')
WHERE AB_CLIENT = 1
COMMIT
GO

BEGIN TRANSACTION
UPDATE TBL_DEV_OL_NEW1
SET Entity = Entity + '' + ' | SB'
WHERE SB_CLIENT = 1
COMMIT
GO

BEGIN TRANSACTION
UPDATE TBL_DEV_OL_NEW1
SET Entity = 'SB'
WHERE SB_CLIENT = 1 And entity is null
COMMIT
go

BEGIN TRANSACTION
UPDATE TBL_DEV_OL_NEW1
SET Entity = Entity + '' + (' | CI')
WHERE CI_CLIENT = 1
COMMIT
GO

BEGIN TRANSACTION
UPDATE TBL_DEV_OL_NEW1
SET Entity = 'CI'
WHERE CI_CLIENT = 1 And entity is null
COMMIT
GO

BEGIN TRANSACTION
UPDATE TBL_DEV_OL_NEW1
SET Entity = Entity + '' + (' | GEMS')
WHERE GEMS_CLIENT = 1
COMMIT
GO

BEGIN TRANSACTION
UPDATE TBL_DEV_OL_NEW1
SET Entity = 'GEMS'
WHERE GEMS_CLIENT = 1 And entity is null
COMMIT
GO

View 1 Replies View Related

IF Else Within A Case Statement

Feb 14, 2006

In my query below i have the results ,The thing to observe in the result set it for the name "Acevedo" , "Abeyta" its not doing a group by and populating the results in the following column.Rather its addind a new row and adding it as 1 in the next row.
I have to populate the counts in one row for common names.Shall i use a if condition within a case block.If yes how?any other work arounds would be appriciated.
Please help
Thanks

select
isnull(replace(Ltrim(Rtrim(P.Lastname)),',',''),'' ) Lastname
, case ProductID
WHEN 22 then count(S.Product)
Else 0
END AS Builders
, case ProductID
WHEN 23 then count(S.Product)
Else 0
END AS Associates
, case ProductID
WHEN 24 then count(S.Product)
Else 0
END AS Affiliates
FROM vwpersons p with (nolock)
join vwSubscriptions S with (nolock)
on S.RecipientID = P.ID
where P.Lastname in (select Ltrim(Rtrim(H.name)) from externaldata.dbo.Hispanicnames H)
group by P.Lastname, S.ProductID
having count(P.LastName)>=1
order by 1

Result set :

Firstname Builders AssociatesAffiliates

Abarca 010
Abascal200
Abelar 100
Abeyta100
Abeyta010
Abreu 100
Abreu 010
Acevedo100
Acevedo050

View 2 Replies View Related

AVG(CASE) Statement - Help Please

Aug 20, 2007

I am trying to get avg score by site, by call type. Columns are Site(varchar), Calltype(varchar), totalscore(float). Calltypes are A, B, C, D. Sites are 1, 2, 3, 4. I can do a straight average statement and only get one calltype.
I want to do a CASE statement to get all average scores for all calltypes.

Select Site, avg(totalscore) as [Avg Score]
FROM DB
WHERE calltype = 'A'
GROUP BY Site

Results

Site Avg Score (for A)
1 85
2 75.5
3 85.33

SELECT Site, AVG(CASE WHEN TotalScore > 0 AND CallType = 'A' THEN Totalscore
ELSE 0 END) AS [Avg Score For A]
FROM DB
GROUP BY Site

Results

Site Avg Score For A
1 i get 8.5
2 i get 37.75
3 i get 36.57
Why am I getting a difference?
Any help is greatly appreciated - thank you

View 1 Replies View Related

SQL CASE Statement

Aug 18, 2004

Hi Ive got a simple query where I want to calculate an average of one number divided by the other ie: avg(x / y)

Im trying to use a case statement to return 0 in the event that y is 0, to avoid a division by zero error. My query is still returning a division by zero error anyway can anybody help?

SELECT CCode, CASE WHEN BS_TOTAL_ASSETS = 0 THEN 0 ELSE AVG(BSCLTradeCreditors / BS_TOTAL_ASSETS) END AS myaverage
FROM [Company/Year]
GROUP BY CCode, BS_TOTAL_ASSETS

Thanks

View 3 Replies View Related

Case Statement

Apr 11, 2008

i ahve one fucniton:
create function fntotalcountcustclas

( @campaign varchar(50), @startdate datetime, @enddate datetime)
RETURNS TABLE
AS
RETURN
( Select t.itemnmbr,t.custclas, t.custclasdescription, t.totalcustclas as totalcount

from
(
select
vi.itemnmbr, replace(vc.custclas,'','Unspecified') as custclas, vc.custclasdescription, count(vc.custclas) as totalcustclas
from vwcustnmbr vc
join vwitemnbmr vi
on vi.sopnumbe=vc.sopnumbe
Where vi.Campaign = @Campaign and (vc.docdate between @startdate and @enddate)

group by vi.itemnmbr,vc.custclas, vc.custclasdescription
) as t
)
when i m executing it:
select * from fntotalcountcustclas('copd','1/1/2008','4/11/2008')
order by totalcount desc

i m getting results like:
itemnmbr,custclas,custclasdescription,totalcount
------------------------------------------------
06-5841 STANDARD Standard(web) 31
06-5840 STANDARD Standard(web) 30
kr-014 STANDARD Standard(web) 72
06-5841 INDPATIENT Patient 12
06-5840 INDPATIENT Patient 9
06-5845 INDPATIENT Patient 6
06-5841 PROGRAM Program 6
06-5841 INST-HOSPITAL Hospital 11
...................

Basically, i ahve to use one condition to get corrrect output related to inputs:

like - i have to input @category varchar(50), @category_value varchar(50)
and if category = 'campaign' then category_value = ''
then output should be itemnmbr sum(totalcount) [whatever should be custclas or custclasdesscription]
itemnmbr sumcount
-----------------
06-5840 52
06-541 101
06-452 26
kr-045 252

and if categroy = 'item' then category_value = any itemnmbrs(06-5840,06-5845,06-5841 etc..)
then output should be
itemnmbr custclas custclasdescription totalcount
-----------------------------------------------------
06-5840 STANDARD Standard(web) 31
06-5840 INDPATIENT Patient 9
06-5840 PROGRAM Program 6
06-5840 INS-HOSPITAL Hospital 17

like that..

can anyone help me to write case statement.
thanks a lot!!

create function fntotalcountcustclas

( @campaign varchar(50), @startdate datetime, @enddate datetime,
@category varchar(50), @category_value varchar(50))
RETURNS TABLE
AS
RETURN
( Select t.itemnmbr,t.custclas, t.custclasdescription, t.totalcustclas as totalcount,
case when category

from
(
select
vi.itemnmbr, replace(vc.custclas,'','Unspecified') as custclas, vc.custclasdescription, count(vc.custclas) as totalcustclas
from vwcustnmbr vc
join vwitemnbmr vi
on vi.sopnumbe=vc.sopnumbe
Where vi.Campaign = @Campaign and (vc.docdate between @startdate and @enddate)

group by vi.itemnmbr,vc.custclas, vc.custclasdescription
) as t
)

View 10 Replies View Related

Case Statement

May 5, 2008

Im running the following sql statement but I dont see the
expected output. There are few differences between acc & cl1, mcc & cl2 , ncr & cl3 but I dont see either 'ONE' or 'TWO' or 'THREE'.
There is even a case where cl3 is null but the sql is not filling in either one or two or three. Query simply returns id & rest as null values.




SELECT P1.id,
CASE
WHEN p1.acc!= p1.cl1 then 'ONE'
WHEN p1.mcc!= p1.cl2 then 'TWO'
when p1.ncr!= p1.cl3 then 'THREE'
Else NULL END
As NOnMatchingColumn
from
(select id, acc, cl1,mcc,cl2,ncr,cl3 from dbo.ml)P1

View 5 Replies View Related

Help With Case Statement

Jun 6, 2008

I'm not sure if I am doing this the right way. In my table I have project ids. Each project id has several activities associated with it. Each project has a starting balance. Each activity posts an expense to the total balance of the project. If the project has enough money to handle the charges made by the activities, all the activity expenses can be "posted". If there isn't enough money, I want to loop through the activities, check to see if there is enough of a balance to "post" the first one, If there is, then I want to re-adjust the balance and check the second activity. I want to scroll through each project/activity to see what can be "posted". Here is what I have so far, but I cannot work out how to change the total balance amount. Hopefully what I am trying to do makes sense!



declare @testId nchar(6)
declare @RowNum int
declare @newBalance int
select top 1 @testId=projID from #ProjIds
set @RowNum = 0

WHILE @RowNum <= (Select Max(temp_id) from #ProjIds)
BEGIN
set @RowNum = @RowNum + 1
set @newBalance = (select top 1 Bal_2300
from #RevRecData
where @testId=projId
order by projID, activity)

select projId, activity, postCr, Bal_2300,
'New_Status' = Case when (postCr <= Bal_2300) then 'Can Clear' else 'Still Check' END,
'New_Balance' = Case when (postCr <= @newBalance) then (@newBalance - postCr) else @newBalance End
from #RevRecData
where @testId=projId
order by projID, activity

select top 1 @testId=projId from #ProjIds
where projId > @testID
END

View 12 Replies View Related

Need Help Using Case Statement

Jun 7, 2008

I've these following table
SEL
Date_Taken | Main_ID | Time | Daily_Rainfall
---------------------------------------------------
...
...
...
4/3/2005 | 202 | 1015 | 2
4/3/2005 | 202 | 1045 | 2
4/3/2005 | 202 | 1215 | 7
4/3/2005 | 203 | 715 | 2
4/3/2005 | 203 | 1345 | 2
4/3/2005 | 203 | 1530 | 7
...
...
...
5/29/2005 | 203 | 1100 | 56
5/29/2005 | 203 | 1130 | 156
5/29/2005 | 203 | 1145 | 256
...
...
...


Station_Info
State | Main_ID
--------------------
SEL | 202
SEL | 203
SEL | 204
SEL | 205
SEL | 209

Main_ID | Month_Year | 3MthCumRf | 6MthCumRf | 9MthCumRf | 12MthCumRf
------------------------------------------------------------------------------
202| 4/30/2005 | 525.8 | 683.11 | 356.33 | 754.33
203| 4/30/2005 | 435.5 | 400.9 | 290.34 | 234.34
204| 4/30/2005 | 265.53 | 453.21 | 543.66 | 753.24
205| 4/30/2005 | 251.38 | 754.33 | 478.34 | 785.22
209| 4/30/2005 | 259.5 | 356.34 | 894.33 | 354.78
202| 5/30/2005 | 565.8 | 383.11 | 756.33 | 254.33
203| 5/30/2005 | 485.5 | 444.9 | 744.34 | 755.34



This query only display Max(Daily_Rainfall) per day from SEL


SELECT t1.MAIN_ID,t1.DATE_TAKEN,t1.TIME,
t1.DAILY_RAINFALL,
CASE WHEN DATEDIFF(mm,t1.DATE_TAKEN,GETDATE()) <=3
THEN t3.[3MthCumRf]
WHEN DATEDIFF(mm,t1.DATE_TAKEN,GETDATE()) <=6
THEN t3.[6MthCumRf]
WHEN DATEDIFF(mm,t1.DATE_TAKEN,GETDATE()) <=9
THEN t3.[9MthCumRf]
WHEN DATEDIFF(mm,t1.DATE_TAKEN,GETDATE()) <=12
THEN t3.[12MthCumRf]
END AS CumRf
FROM
(SELECT ROW_NUMBER() OVER(PARTITION BY DATE_TAKEN,MAIN_ID
ORDER BY DAILY_RAINFALL DESC) AS RowNo,* FROM dbo.SEL)t1
INNER JOIN dbo.STATION_INFO t2 ON t2.MAIN_ID=t1.MAIN_ID AND
t1.RowNo=1 INNER JOIN dbo.LT t3 ON t3.STATION_ID =t2.STATION_ID
AND t1.DATE_TAKEN>=CONVERT(VARCHAR(10),DATEADD(m,-3,GETDATE()),101)
ANDt1.DATE_TAKEN<CONVERT(VARCHAR(10), GETDATE(), 101)
WHERE t2.STATE='SEL'
ORDER BY MAIN_ID,DATE_TAKEN,TIME

In my query, i still can query if last3month using CASE WHEN DATEDIFF(mm,t1.DATE_TAKEN,GETDATE()) <=3 THEN t3.[3MthCumRf]

How to adjust my CASE statement
if Main_ID=203, Date_Taken=5/5/2005,

i should pickup following rows
Main_ID | Month_Year | 3MthCumRf | 6MthCumRf | 9MthCumRf | 12MthCumRf
-------------------------------------------------------------------
203| 5/30/2005 | 485.5 | 444.9 | 744.34 | 755.34

if Main_ID=203, Date_Taken=4/5/2005,
i should pickup following rows
Main_ID | Month_Year | 3MthCumRf | 6MthCumRf | 9MthCumRf | 12MthCumRf
203| 4/30/2005 | 435.5 | 400.9 | 290.34 | 234.34

Need someone help... plz

View 20 Replies View Related

Case When Statement

Aug 22, 2013

In my temptable I'm still trying to replace NULL values with 0 (zero).I tried ISNULL and that didn't work.I tried ISNULL and it didn't work. I was told by a senior developer I work with that I should do something like a case when. whatever that is.

INSERT INTO #TEMPLEASEDOLLARSSUBMITTED (SalesName, UserID, LeaseDollarsSubmitted)
(
SELECT (FirstName + '' + LastName)AS [Sales Team Member], Usr.UserID,
SUM (ISNULL(MerAppEqL.MonthlyPayment,0))AS [Leases $ Submitted]
FROM MerchantAppEquipmentLease MerAppEqL WITH(NOLOCK)
INNER JOIN MerchantAppEquipment MerAppEqt ON MerAppEqL.EquipmentLeaseID = MerAppEqt.LeaseNumber

[code]...

Or should I have put the ISNULL when I updated #TEMPDASHBOARD because that is where the NULL values show up. They don't show up in #TEMPLEASEDOLLARSSUBMITTED table?

View 4 Replies View Related

Case Statement

Jan 3, 2006

Hello,
I have a sql statement that uses case statement to calculate a variable, I would like to use that variable in the same sql statement to calculate a different variable.
In my code Wed_Var is calculated, but since I dont know a way to use the Wed_Var in Wed_Adj, I copy the whole formula again.
Any help is appreciated.

Thanks

SELECT TOP 100 PERCENT dbo.VIEW_ManPlan_Dock_Prev_4WK.Terminal,
Wed_Var = CASE WHEN dbo.VIEW_ManPlan_Dock_Prev_Current.Tue = 0 THEN dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Tue_Var WHEN (dbo.VIEW_ManPlan_Dock_Prev_Current.Mon
+ dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date < .75 THEN .75 WHEN (dbo.VIEW_ManPlan_Dock_Prev_Current.Mon + dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date > 1.25 THEN 1.25 ELSE (dbo.VIEW_ManPlan_Dock_Prev_Current.Mon + dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date END,
Wed_Adj = CASE WHEN dbo.VIEW_ManPlan_Dock_Prev_Current.Tue = 0 THEN dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Tue_Var * (dbo.VIEW_ManPlan_Dock_Prev_4Wk.Wed
/ 4) WHEN (dbo.VIEW_ManPlan_Dock_Prev_Current.Mon + dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date < .75 THEN .75 * (dbo.VIEW_ManPlan_Dock_Prev_4Wk.Wed / 4)
WHEN (dbo.VIEW_ManPlan_Dock_Prev_Current.Mon + dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date > 1.25 THEN 1.25 * (dbo.VIEW_ManPlan_Dock_Prev_4Wk.Wed / 4)
ELSE (dbo.VIEW_ManPlan_Dock_Prev_4Wk.Wed / 4) * ((dbo.VIEW_ManPlan_Dock_Prev_Current.Mon + dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date) END,
Week_To_Date = CASE WHEN dbo.VIEW_ManPlan_Dock_Prev_Current.Tue = 0 THEN dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date + (dbo.VIEW_ManPlan_Dock_Prev_4Wk.Wed
/ 4)
* dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Tue_Var WHEN (dbo.VIEW_ManPlan_Dock_Prev_Current.Mon + dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date < .75 THEN dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date + (dbo.VIEW_ManPlan_Dock_Prev_4Wk.Wed
/ 4) * .75 WHEN (dbo.VIEW_ManPlan_Dock_Prev_Current.Mon + dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date > 1.25 THEN dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date + (dbo.VIEW_ManPlan_Dock_Prev_4Wk.Wed
/ 4) * 1.25 ELSE dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date + (dbo.VIEW_ManPlan_Dock_Prev_4Wk.Wed / 4)
* ((dbo.VIEW_ManPlan_Dock_Prev_Current.Mon + dbo.VIEW_ManPlan_Dock_Prev_Current.Tue)
/ dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Week_To_Date) END
FROM dbo.VIEW_ManPlan_Dock_Prev_4WK INNER JOIN
dbo.VIEW_ManPlan_Dock_Prev_Current ON
dbo.VIEW_ManPlan_Dock_Prev_4WK.Terminal = dbo.VIEW_ManPlan_Dock_Prev_Current.Terminal INNER JOIN
dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday ON
dbo.VIEW_ManPlan_Dock_Prev_4WK.Terminal = dbo.VIEW_ManPlan_Dock_Prev_Run_Tuesday.Terminal
ORDER BY dbo.VIEW_ManPlan_Dock_Prev_4WK.Terminal

View 2 Replies View Related

Case Statement

Mar 26, 2007

(CASE WHEN (Sheet1$.NOTES = 'unscheduled visit')
THEN 1 END) AS [unscheduled visit]

I am not sure how to use the Case statement with more than one Note
ie
unscheduled visit
early termination

I tried

(CASE WHEN (Sheet1$.NOTES = 'unscheduled visit') OR (Sheet1$.NOTES = 'early termination')
THEN 1 END) AS [unscheduled visit]

(CASE WHEN (Sheet1$.NOTES = 'unscheduled visit'OR'early termination')
THEN 1 END) AS [unscheduled visit]

I am confused on the proper syntax. All the example I can find use a numeric value. Thanks!

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved