Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Tuesday, March 27, 2012

Help with Case Statement

I have the following code in which I need to check something in the ELSE. The problem is how to form it correctly. I could use a cursor I guess to transverse through the records.

In the Else, I want to:

1) Check the count of the results of my statement. IF > 1 then check to see if m.original is between lowlimit and highlimit for any of those records found
2) If m.original is between the lowlimit and highlimit, then select Fee1 from FeeScheduleDetails

m.original and m.FeeSchedule is out here somewhere, just know this...it's part of the query that you don't see

CASE WHEN Len(c.FeeSchedule) < 3 then
CONVERT(int, c.feeSchedule)
ELSE
Select Count(*) FROM FeeScheduleDetails fd
INNER JOIN Master m ON m.FeeSchedule = fd.code

IF Count(*) > 3
Check to see if m.original is BETWEEN fd.lowlimit AND fd.highlimit
If yes, then bring me back fee1, if no then just bring me back m.FeeSchedule
END AS FeeSchedule

Master

FeeSchedule

FeeScheduleDetails
-
Code
LowLimit
HighLimit
Fee1

? Hi dba123, In your qeury pseudo-code, where is the alias c (used in c.FeeSchedule) defined? It's easier to help you if you post CREATE TABLE statements for your table structures, INSERT statements with some rows of sample data and the expected results of the query. Not only will that help others understand what you ask, it also enables them to easily test what they post. -- Hugo Kornelis, SQL Server MVP <dba123@.discussions.microsoft.com> schreef in bericht news:7fb6e0f7-ae20-451c-abee-677d4d3ee6f8@.discussions.microsoft.com... I have the following code in which I need to check something in the ELSE. The problem is how to form it correctly. I could use a cursor I guess to transverse through the records.In the Else, I want to:1) Check the count of the results of my statement. IF > 1 then check to see if m.original is between lowlimit and highlimit for any of those records found2) If m.original is between the lowlimit and highlimit, then select Fee1 from FeeScheduleDetailsm.original and m.FeeSchedule is out here somewhere, just know this...it's part of the query that you don't seeCASE WHEN Len(c.FeeSchedule) < 3 thenCONVERT(int, c.feeSchedule)ELSESelect Count(*) FROM FeeScheduleDetails fdINNER JOIN Master m ON m.FeeSchedule = fd.codeIF Count(*) > 3Check to see if m.original is BETWEEN fd.lowlimit AND fd.highlimitIf yes, then bring me back fee1, if no then just bring me back m.FeeScheduleEND AS FeeScheduleMasterFeeScheduleFeeScheduleDetails-CodeLowLimitHighLimitFee1|||

thanks for the heads up. Here's the entire query...and a new attept at fee1

INSERT INTO ReportingServer.dbo.DCR

SELECT

m.customer,

c.name,

c.customer,

c.state,

CASE WHEN Len(c.FeeSchedule) < 3 THEN

CONVERT(int, c.feeSchedule)

WHEN Len(c.FeeSchedule) > 3 THEN

SELECT fd.Fee1 FROM FeeScheduleDetails fd

where c.feeSchedule = fd.code AND m.original BETWEEN fd.LowLimit AND fd.HighLimit

ELSE

CONVERT(int, c.feeSchedule)

END AS FeeSchedule,

m.Branch,

CASE WHEN ph.batchtype = 'PUR' OR ph.batchtype = 'PAR' OR ph.batchtype = 'PCR' Then

(ph.totalpaid - ph.ForwardeeFee)

ELSE

0.00

END AS [Posted Amount],

ph.systemmonth,

ph.datepaid,

ph.totalpaid,

ph.batchtype,

m.desk,

0 AS [New Old CC],

0 AS [New Old PDC],

'In-House' AS Type,

1 AS Active,

ph.UID,

m.number,

dc.amount CC,

p.amount AS PDC,

m.original,

CONVERT(money, ph.OverPaidAmt),

0,

0,

''

FROM dbo.Master m (NOLOCK) LEFT JOIN dbo.payhistory ph ON m.number = ph.number

LEFTJOIN dbo.DebtorCreditCards dc ON dc.number = m.number

LEFTJOIN dbo.pdc p ON p.number = m.number

LEFTJOIN dbo.Customer c ON c.Customer = m.Customer

LEFTJOIN Apex_ReportingServer.dbo.FeeGoal fg ON fg.CustomerID = c.Customer

GROUP BYm.customer,

c.name,

c.customer,

c.state,

c.FeeSchedule,

m.Branch,

ph.OverPaidAmt,

ph.systemmonth,

ph.datepaid,

ph.totalpaid,

ph.batchtype,

m.desk,

ph.UID,

m.number,

dc.amount,

p.amount,

m.original ,

ph.systemmonth,

ph.systemyear,

ph.ForwardeeFee

HAVINGph.systemmonth = datepart(mm, getdate()) AND ph.batchtype <> 'DA' AND

ph.batchtype <> 'DAR' AND ph.systemyear = datepart(yy, getdate())

AND (c.Name is not null AND c.Name <> '')

ORDER BY m.customer

|||? Hi dba123, Thanks - but you didn't post CREATE TABLE and INSERT statements, so I still can't test any code, nor see what exactly you try to do. Anyway - I'll respond to your other post; it looks to be a simplified version of this problem. If you do need more help in this thread, then add some CREATE TABLE and INSERT statements and expected results, and I'll have a look at it. -- Hugo Kornelis, SQL Server MVP <dba123@.discussions.microsoft.com> schreef in bericht news:662f6401-ea73-4c37-a98e-dd9267c0ed2c@.discussions.microsoft.com... thanks for the heads up. Here's the entire query...and a new attept at fee1 INSERT INTO ReportingServer.dbo.DCR SELECT m.customer, c.name, c.customer, c.state, CASE WHEN Len(c.FeeSchedule) < 3 THEN CONVERT(int, c.feeSchedule) WHEN Len(c.FeeSchedule) > 3 THEN SELECT fd.Fee1 FROM FeeScheduleDetails fd where c.feeSchedule = fd.code AND m.original BETWEEN fd.LowLimit AND fd.HighLimit ELSE CONVERT(int, c.feeSchedule) END AS FeeSchedule, m.Branch, CASE WHEN ph.batchtype = 'PUR' OR ph.batchtype = 'PAR' OR ph.batchtype = 'PCR' Then (ph.totalpaid - ph.ForwardeeFee) ELSE 0.00 END AS [Posted Amount], ph.systemmonth, ph.datepaid, ph.totalpaid, ph.batchtype, m.desk, 0 AS [New Old CC], 0 AS [New Old PDC], 'In-House' AS Type, 1 AS Active, ph.UID, m.number, dc.amount CC, p.amount AS PDC, m.original, CONVERT(money, ph.OverPaidAmt), 0, 0, '' FROM dbo.Master m (NOLOCK) LEFT JOIN dbo.payhistory ph ON m.number = ph.number LEFT JOIN dbo.DebtorCreditCards dc ON dc.number = m.number LEFT JOIN dbo.pdc p ON p.number = m.number LEFT JOIN dbo.Customer c ON c.Customer = m.Customer LEFT JOIN Apex_ReportingServer.dbo.FeeGoal fg ON fg.CustomerID = c.Customer GROUP BY m.customer, c.name, c.customer, c.state, c.FeeSchedule, m.Branch, ph.OverPaidAmt, ph.systemmonth, ph.datepaid, ph.totalpaid, ph.batchtype, m.desk, ph.UID, m.number, dc.amount, p.amount, m.original , ph.systemmonth, ph.systemyear, ph.ForwardeeFee HAVING ph.systemmonth = datepart(mm, getdate()) AND ph.batchtype <> 'DA' AND ph.batchtype <> 'DAR' AND ph.systemyear = datepart(yy, getdate()) AND (c.Name is not null AND c.Name <> '') ORDER BY m.customer|||So are you asking for my table structure then? The table has already been created...so are you asking for the erd ?|||

I am not sure what you are asking. I have also never seen a CASE statement used in this way. CASE statements are always used within a SELECT clause to select a result value to display in the column based on the value in a particular row. SQL has an IF condition of form:

IF.....

BEGIN

END

ELSE

BEGIN

END

Firstly I suggest you use IF that instead. Is your IF statement returning multiple values, or just one value? If it is just returning one value (and with a count(*) you normally only return one valuer, unless using a GROUP BY) then use and IF, otherwise use a case statement. IF example below)

declare @.result int

declare @.lowlimit int

declare @.highlimit int

IF Len(c.FeeSchedule) < 3

BEGIN

set @.result = CONVERT(int, c.feeSchedule)

END

ELSE
work out @.lowlimit and @.highlimit here.....

delcare @.cnt int

Select @.cnt = Count(*) FROM FeeScheduleDetails fd
INNER JOIN Master m ON m.FeeSchedule = fd.code

IF @.cntBETWEEN @.lowlimit AND @.highlimit

BEGIN

@.result = (get Fee1......)

END

ELSE

BEGIN

@.result = (get m.FeeSchedule.....)

END

END

Otherwise, if you want the second conditional to be a CASE statement, you will need to rewrite it accordingly

Clarity Consulting

|||I don't think you can do a select statment inside of a CASE statement. Store the result in a variable, and then select that in the CASE statement instead if possible. Otherwise, get the value from a JOIN instead, then you just need to select the column in the CASE...WHEN .. THEN statement.|||? Hi dba123, Sorry for the delayed reply... >>So are you asking for my table structure then? The table has already been created...so are you asking for the erd ? What I'm askking you for is a bunch of statements that I can copy and paste into Query Analyzer and run to recreate the problem. To give you a very simplified example: instead of asking "how to get the lowest wage for each department", you'd have to post some SQL: CREATE TABLE Personnel (EmpID int NOT NULL PRIMARY KEY, DeptID int NOT NULL, Wage decimal(7,2) NOT NULL) go INSERT INTO Personnel (EmpID, DeptID, Wage) VALUES (1, 1, 20000) INSERT INTO Personnel (EmpID, DeptID, Wage) VALUES (2, 1, 30000) INSERT INTO Personnel (EmpID, DeptID, Wage) VALUES (3, 2, 15000) INSERT INTO Personnel (EmpID, DeptID, Wage) VALUES (4, 3, 20000) go And then, you'd add the required results: DeptID LowestWage 1 20000 2 15000 3 20000 Anyone can now copy the SQL statements, execute them in a test database, try some queries and finally come up with this reply: SELECT DeptID, MIN(Wage) AS LowestWage FROM Personnel GROUP BY DeptID Of course, the example above is pretty basic. Your questions (at least the ones I've seen here) are a lot more complex. Trying to answer them without knowing exactly how the tables look (i.e. columns, datatypes, constraints, indexes, defaults, ... everything you'd see in a CREATE TABLE statement), what kind of data is in them (i.e. the INSERT statements) and what results you expect to get makes it more an exercise at guessing, or even mind reading, than an exercise in writing SQL. I'm pretty good at writing SQL. I think I help a lot of people with my skills in this and other forums and groups. But my clairvoyance skills are lousy. In other words: if you don't explain the problem clear enough, you're likely to get no answer or a wrong answer from me - and probably from others as well. From experience, I know that most probles are best explained by posting CREATE TABLE statements, INSERT statements, expected results and a short explanation. Check out www.aspfaq.com/5006 for more information about this and for some techniques that can help you assemble the information for your posts. I hope this helps. -- Hugo Kornelis, SQL Server MVP|||thanks, I was using the case statement to determine which to return back as FeeSchedule. It's dependent on the lenght of a certain field. I the field was>3 I needed to do a lookup else, juse use that field.|||thanks

NNTP User
. Sometimes I don't have all those statements created because the statement I'm working on is it and is my only attempt/approach at the time! Yes, I could have posted some data examples though. Thanks for your explanation.

Friday, March 9, 2012

Help w/ SqlClientPermission

Hello!

I'm currently working on a project consisting in rewriting VB 6.0 applications into VS 2005 applications. I already have the form designed in VS '05 w/ the controls, and I'm connected to a SQL server 2000 database. I've also created the different data adapters and datasets, which in VS 2005, have also created BindingSources and BindingNavigators. But, when I run the project, I am getting the following error, and the form doesn't appear:

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I have been trying to find ways to get around it, but I'm not that successful. I have gone online on the Microsoft website and found a host of comments from other people, but I can't relate theirs to my problem. I understand that my program needs to be granted this permission for it to run, but I can't seem to know what and where to begin resolving it. Here's also what I've found online about how to resolve it:

To grant the required permissions to a custom assembly, follow these steps:

1. Assert permissions in your custom assembly.

2. Make the custom assembly available to your project.

3. Reference the custom assembly in your project.

4. Modify the code access security (CAS) settings for your custom assembly.

Can anyone who has encountered this kind of error tell me if these are the steps I need to take to solve it?

Also, is teh custom assembly the AssemblyInfo.vb file or is it obtained by right-clicking the project in the Solution Explorer and pointing at the properties?

Thanks very much for any help I can help.

Have a wonderful day.

This is a CAS policy which could be set at domain level and enherited by your computer. The SQLClient assembly is not rated as trusted in the domain/Area you want to run the application (either locally or over the network which is in common not allowed / trusted). YOu can see the configured permissions using the .Net Framework configuration tool.

Jens K. Suessmeyer

http://www.sqlserver2005.de

Friday, February 24, 2012

Help retreving Value form sql reader

hello,

I have tried myReader.GetSqlString, GetSqlValue, GetSqlInt16, etc...etc...

But I keep getting an error (System.InvalidCastException was caught
Message="Conversion from type 'SqlInt32' to type 'String' is not valid."
Source="Microsoft.VisualBasic"
StackTrace:
at Microsoft.VisualBasic.CompilerServices.Conversions.ToString(Object Value)
at ImportDelimitedFile.SumCurrentAmount() in C:\Documents and Settings\emg3703\My Documents\Visual Studio 2005\EscuelasComunidad\ImportDelimitedFile.aspx.vb:line 556)

Here is my code:

Public Function SumCurrentAmount()As String

Dim sqlconnAs New SqlConnection(ConfigurationManager.ConnectionStrings("GDBRemitanceConnectionString1").ConnectionString)
Dim sqlcmdAs New SqlCommand("SELECT SUM(CONVERT (Int, Field_6)) AS TotalAmount, Record_Type FROM tblTempWorkingStorage_NACHA GROUP BY Record_Type HAVING (Record_Type ='6')", sqlconn)

Try

sqlcmd.Connection.Open()
Dim myReaderAs SqlDataReader
myReader = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)
If myReader.Read()Then

SumCurrentAmount =CType(myReader.GetSqlValue(0),String)
Return SumCurrentAmount

Else

End If
myReader.Close()

Catch

End Try
sqlcmd.Connection.Close()

End Function

I need to know which "GetSql...(type) should I used to extract field numbre one from myReader.

Thanks a lot,

Try to change this line:

SumCurrentAmount =CType(myReader.GetSqlValue(0),String)

to:

SumCurrentAmount = (myReader.GetDecimal(0)).ToString()

For more information about mapping SqlDbTypes to CLR data types, you can refer to:

http://msdn2.microsoft.com/en-us/library/system.data.sqldbtype.aspx

Sunday, February 19, 2012

Help required!

Hi all

I am creating a web services application in Visual Studio Dot net
which links to a MS SQL database.

I need to create a form which lets the user pick his field of
choice(doesnt matter what it is..) using drop down boxes,radio buttons
etc and query the database according to what he has picked and
retrieve only those columns and rows.

The thing is, I do not want to hardcode the queries using
OleDbDataAdapter or SqlDataAdapter, but want the query to be generated
on the fly, once the user picks his fields from the form.

I'd greatly appreciate any help.

Thanks,
mSeems you are looking to provide ad-hoc reporting capabilities. To avoid
hard-coding queries you would have to access the SQL Server meta-data to
retrieve information about tables and to provide options for users to pick
tables and columns. You can start by looking at the information schema views
in the SQL Server documentation. Here is one example of a query that returns
tables and columns:

SELECT c.table_catalog AS 'Database Name',
c.table_schema AS 'Owner',
c.table_name AS 'Table Name',
c.column_name AS 'Column Name',
c.data_type AS 'Column Data Type'
FROM INFORMATION_SCHEMA.COLUMNS c
INNER JOIN INFORMATION_SCHEMA.TABLES t
ON t.table_catalog = c.table_catalog
AND t.table_schema = c.table_schema
AND t.table_name = c.table_name
WHERE t.table_type = 'BASE TABLE'

Since the table and column names may not mean much to users, you may want to
build a mapping table with descriptive names. That involves some hard-coding
and maintenance (best stored in a table that you can join easily) to update
when a new table/column is added or changed, but greatly improves the user
experience.

Next you would allow selection of columns and placing filters (the WHERE
clause of the query). A good idea is to enforce a requirement to have at
least one condition. Users tend to forget about adding filters and could
possibly dump the whole table out. At this point it is very important to
check the column type and perform verification on any parameters entered.

Last is to build a dynamic query and return the results to the user. A good
reading for dynamic queries is Erland Sommarskog's article here:
http://www.sommarskog.se/dynamic_sql.html. Pay attention to the SQL
injection section as this is very common for ad-hoc query systems.

This is a very simplified approach to what you are looking for. It can get a
lot more complex if you need to provide special operations like summary
queries, or if you decide to provide capabilities to join multiple tables.

HTH,

Plamen Ratchev
http://www.SQLStudio.com|||On 27 Feb 2007 14:40:23 -0800, madhumita.iyengar@.gmail.com wrote:

Quote:

Originally Posted by

>Hi all
>
>I am creating a web services application in Visual Studio Dot net
>which links to a MS SQL database.
>
>I need to create a form which lets the user pick his field of
>choice(doesnt matter what it is..) using drop down boxes,radio buttons
>etc and query the database according to what he has picked and
>retrieve only those columns and rows.
>
>The thing is, I do not want to hardcode the queries using
>OleDbDataAdapter or SqlDataAdapter, but want the query to be generated
>on the fly, once the user picks his fields from the form.
>
>I'd greatly appreciate any help.
>
>Thanks,
>m


In addition to Plamen's suggestions, you might look into the report
builder part of Sql Server Reporting Services. The programmer sets up
the appropriate data model, and the user configures the report. There
is something of a learning curve for the user but designing a report
can be fairly trivial.|||On 27 Feb 2007 14:40:23 -0800, madhumita.iyengar@.gmail.com wrote:

Quote:

Originally Posted by

>Hi all
>
>I am creating a web services application in Visual Studio Dot net
>which links to a MS SQL database.
>
>I need to create a form which lets the user pick his field of
>choice(doesnt matter what it is..) using drop down boxes,radio buttons
>etc and query the database according to what he has picked and
>retrieve only those columns and rows.
>
>The thing is, I do not want to hardcode the queries using
>OleDbDataAdapter or SqlDataAdapter, but want the query to be generated
>on the fly, once the user picks his fields from the form.
>
>I'd greatly appreciate any help.
>
>Thanks,
>m


And you'll likely get more replies if you're specific in your post,
rather than just Help Required!.

help required

i have created registration form which consist of 6 webform, for each user i had given option save and come back later (say on webform3), when userlogin for the second time without complete registration i.e, on the 6th webform i had given save option then only it enters into database. the problem is when user login in for the second time he should be redirected to same page(webform3)

so i need help from urside

I beleive you are saving this information in database table. i don't now what table structure you are using in your application. but i think you are saving that information in user table then just create a web user control and place it on the top of the each page. that user control will check with database that on which page access last time and redirect the request by using response.redirect/server.transfer.

|||

This tutorial video (one of the many excellent tutorials available at www.asp.net) will demonstrate this for you.

http://asp.net/learn/videos/view.aspx?tabid=63&id=47