MSSQL Nested Queries

Apr 7, 2007

Hi,

I have been trying to write a nested query, however i am facing errors while executing that.

The code is as below.

<%

Dim MyConnection = New SqlConnection()

MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("AppConnectionString1").ConnectionString

MyConnection.Open()

Dim cmd As New SqlCommand

Dim rs As SqlDataReader

Dim rs2 As SqlDataReader

Dim query = "select count(bank_id) from bank_master"

Dim query2 As String

cmd.CommandType = CommandType.Text

cmd.Connection = MyConnection

cmd.CommandText = query

rs = cmd.ExecuteReader

If rs.Read() Then

Dim rec = rs(0)

If (rec > 0) Then

Response.Write(rec & " banks registered in the system")

rs.Close()

query2 = "select * from bank_master order by bank_id"

rs2 = cmd.ExecuteReader(query2)

If rs2.Read() Then

Response.Write(rs2(0))

Else

Response.Write("No banks yet registered in the system")

End If

Else

Response.Write("No banks yet registered in the system")

End If

End If

%>

 

The error message that i am getting at runtime:



Server Error in '/Accounts' Application.


Input string was not in a correct format.

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.FormatException: Input string was not in a correct format.

Source Error:







Line 117:
Line 118: query2 = "select * from bank_master order by bank_id"
Line 119: rs2 = cmd.ExecuteReader(query2)
Line 120: If rs2.Read() Then
Line 121: Response.Write(rs2(0))


Source File: E:WEBHOMEAccountsank.aspx    Line: 119

 Could you please help?

 

Best Regards,

Debashis

View 4 Replies


ADVERTISEMENT

Nested Queries

Mar 15, 2005

I have this table record:

PHP Code:




 ID |    NUMBER    |   DSTART   |    DEND    |     ADDRESS     |
----------------------------------------------------------------
 1  | 9524123      | 12 Dec 95  | 24 Dec 95  | London          |
 2  | 9524123      | 06 Jan 96  | 15 Jan 96  | Paris           |
 3  | 084521       | 12 Mar 96  | 15 May 96  | New York        |
 4  | 084521       | 22 Aug 96  | 25 Aug 96  | Sidney          |
 --------------------------------------------------------------- 





Now, I need to build a query to show only the latest DTSTART date
for each NUMBER. The result would be something like this:

PHP Code:




 ID |    NUMBER    |   DSTART   |    DEND    |     ADDRESS     |
----------------------------------------------------------------
 2  | 9524123      | 06 Jan 96  | 15 Jan 96  | Paris           |
 4  | 084521       | 22 Aug 96  | 25 Aug 96  | Sidney          |
 --------------------------------------------------------------- 





Can you guys help me to build the queries? Thanks in advance.

View 2 Replies View Related

Nested Queries

Nov 30, 2007

Hi,

I apologize if this is not the section where this should be posted.

Below is a link to a post I made in the Visual Basic forum. Now that I think about it, it may be more of a SQL question than a VB one.

I'm trying to run a query on the result of a query. Thank in advance for any help.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2486926&SiteID=1

View 4 Replies View Related

Nested And Aggregate Queries

Nov 14, 2013

I have a the following fields in a table TblToDo

[ToDoID] [int] IDENTITY(1,1)
[ToDoReferralID] [int]
[ToDoDate] [datetime]
[ToDoCompleteBy] [datetime]
[ToDoCompleted] [datetime]

and want to produce a query to show the with following

All Grouped by [ToDoReferralID]
Count [ToDoID] AS [ToDoToTal]
Count [ToDoID]WHERE [ToDoCompleted] IS NULL AS [ToDoIncomplete]
Count [ToDoID]WHERE [ToDoCompleted] IS NULL AND [ToDoCompleteBy] <= GETDATE() AS [IncompleteUTarget]
Count [ToDoID]WHERE [ToDoCompleted] IS NULL AND [ToDoCompleteBy] > GETDATE()AS [IncompleteOTarget]

I can manage a single aggregate but where to being trying to incorporate all into one query.

View 6 Replies View Related

No Nested Queries Allowed

Jan 29, 2007

Hi all,

I need to rewrite the following query without a nested query (stupid mysql 4.0.25. Can anyone lend a hand?

SELECT name from `list` where name not in (
SELECT DISTINCT b.name from ` armor ` a,` list` b where b.name = a.name
);

View 4 Replies View Related

Passing Parameters To Nested Parameter Queries

Jul 20, 2005

Though I am a novice to MS SQL server (2000 I believe), I can do almost!everything I need. Maybe not efficiently, but usefully. However, I havea problem -- a complex query problem...I can create a parameter query in a stored procedure, but how do I usethe result set of a parameter query in a select query (in the same oranother sp)? In short, if a select query contains a result table that isgenerated as a parameter query, how do I pass the parameter through theselect query to the nested parameter query?For example, if I have a sp parameter query called [e_typerows], I couldwrite the following select query which uses the (single) result set from[e_typerows] plus other tables or views:SELECT TOP 100 PERCENT bi_occ_01_e.row, bi_occ_01_e.pos,bi_dictionary_e.typestring, bi_occ_01_e.shadowFROM bi_dictionary_e INNER JOIN(bi_occ_01_e INNER JOIN[e_typerows] ON bi_occ_01_e.row = [e_typerows].row) ONbi_dictionary_e.typeid = bi_occ_01_e.typeidORDER BY bi_occ_01_e.row, bi_occ_01_e.posEven though [e_typerows] is a (storted procedure) parameter query thiswill work IF my parameter in [e_typerows] has a default, say "yyyy". Inthe default case no parameter needs passing. But what if it doesn't havea default value or if I need to pass a parameter to it?Is there any way to replace[e_typerows]in the above query with somethinglike [e_typerows @myparameter='xxxx']? (Maybe I should try that! I'veseen nothing about it though.)My parameter query, [e_typerows], looks like this in fact:@typestringparameter varchar(100) = "yyyy"SELECT dbo.bi_dictionary_e.typestring, dbo.bi_occ_01_e.rowFROM dbo.bi_occ_01_e INNER JOINdbo.bi_dictionary_e ONdbo.bi_occ_01_e.typeid = dbo.bi_dictionary_e.typeidGROUP BY dbo.bi_dictionary_e.typestring,dbo.bi_occ_01_e.rowHAVING (dbo.bi_dictionary_e.typestring = @typestringparameter)Any suggestions would be greatly appreciated! (For the moment, I firstgenerate the parameter query result set, then I loop through each row ofthat result set and do a select query with that row as a parameter --very complicated!, though it does work.)

View 3 Replies View Related

SQL Server 2012 :: Structure For Multiple Nested Queries

Feb 27, 2014

I am using Server 2012 and very new to SQL. I have a request from a physician for a list of his patients that meet a criteria. This is stored in a temp table names #cohort.

Using this cohort he wants each row to be one patient with a list of labs, vitals, etc. Three items are the most recent lab value and date. I could query each lab individually and place it into a temp table and then join all temp tables at the end, but I am trying to move past that and have all labs in one temp table. All temp tables are joined with PatientSID.

I tried to do something for just 2 labs, but it is not working. There could be nulls values when joined with the #cohort table.

Individually the SELECT statements pull in the most recent lab value and date, but I cannot get them into a temp table with one row of PatientSID and then the lab value and date if they exist.

IF OBJECT_ID ('TEMPDB..#lab') IS NOT NULL DROP TABLE #lab
SELECT
cohort.PatientSID
,SubQuery1.LabChemResultNumericValueAS 'A1c%'
,SubQuery1.LabChemCompleteDateTimeAS 'A1c% Date'
,SubQuery2.LabChemResultNumericValueAS 'LDL'

[Code] .....

View 1 Replies View Related

Nested Queries, Stored Procedures, Temporary Table

Jul 23, 2005

Hi,I'm adapting access queries to sql server and I have difficulties withthe following pattern :query1 : SELECT * FROM Query2 WHERE A=@param1query 2: SELECT * FROM Table2 WHERE B=@param2The queries are nested, and they both use parameters.In MS Acccess the management of nested queries with parameters is soeasy (implicit declaration of parameters, transmission of parametersfrom main query to nested query)that I don't know what the syntax should be for stored procedures.The corresponding stored procedure would be something likeCREATE TABLE #TempTable (...table definition...)INSERT INTO #TempTable ExecProc spQuery2 @Param2SELECT * FROM #TempTable WHERE A=@Param1And spQuery2 would be : SELECT * FROM Table2 WHERE B=@ParamI was wondering if this syntax would work and if I can skip theexplicit declaration of #TempTable definition.Thanks for your suggestions.

View 5 Replies View Related

How Many Result-rows Does Mssql Return Should Be Used Asynchronous Method To Use Mssql Cursor?

Aug 11, 2004

How many result-rows does mssql return should be used asynchronous method to use mssql cursor, can get the best performance in any time in any result offset?

i want to make the cursor fast in any time whatever how many results returned

View 2 Replies View Related

Database Migration Plan - (mssql/msde To -&> Pgsql/mssql)

Feb 10, 2008

Hi,

i was planning to create a database migration tool ..
its a certain database of a DMS (document management system) to
another DMS (two different DMS)... from DMS using msde 2000 server .. and tranfer to a DMS using a postgre sql or mssql .. depends ..

they have different table structures and names . . :D

i was thing of what language shall i use.. or what language is the best to work on this kind of project :)

hoping for your kind help guys. thanks :)



br
Frozenice

View 1 Replies View Related

Server Configuration For MSSQL 2000 And MSSQL 2005

Sep 6, 2006

Does enabling/disabling Data Execution Prevention have a performanceimpact on SQL 2000 or SQL 2005?For SQL best performance - how should I configure for:Processor Scheduling:Programs or Background servicesMemory Usage:Programs or System Cache

View 9 Replies View Related

Creating Index In MSSQL 2000 From MSSQL 2005

Mar 24, 2008

Hi,

I am a bit new to the MSSQL server. In our application, we use so many SQL queries. To imporve the performance, we used the Database enigine Tuning tool to create the indexes. The older version of the application supports MSSQL 2000 also. To re-create these new indexes, I have an issue in running these "CREATE INDEX" commands as the statements generated for index creation are done in MSSQL 2005. The statements include "INCLUDES" keyword which is supported in MSSQL 2005 but not in MSSQL 2000.

Ex:-

CREATE INDEX IND_001_PPM_PA ON PPM_PROCESS_ACTIVITY

(ACTIVITY_NAME ASC, PROCESS_NAME ASC, START_TIME ASC, ISMONITORED ASC)

INCLUDE

(INSTANCE_ID, ACTIVITY_TYPE, STATUS, END_TIME, ORGANIZATION);


Any help in creating such indexes in 2000 version is welcome.

Thanks,
Suresh.

View 2 Replies View Related

Generating Script For MSSQL 2000 From MSSQl 2005?

May 3, 2008

Hello
We are using SQL 2005 and now we are planning to use SQL 2000. what are the ways to do the process.

We taken the script spcificall for 2000 and run it in SQL 200. But we are getting the error in SCRIPT?

Could you please give me the step to do?

Thanks,
Sankar R

View 6 Replies View Related

Run Mssql 6.5 Client And Mssql 7.0 Server On Same Nt Workstaton?

Oct 26, 1999

Hello:

I am currently work on mssql 6.5. On my workstation, I have mssql 6.5
cient software.

However, I would like to install mssql 7.0 server on my nt workstation
and work with it to become familiar with 7.0. Can I install mssql 7.0
server on my nt workstation? Can mssql 6.5 client coexist with mssql 7.0
on the same machine if they are in different directories?

Thanks.

David Spaisman

View 1 Replies View Related

MSSQL Express 2005 Vs. MSSQL 2000

Jun 15, 2006

Ben writes "I have a sql script that doesn't function very well when it's executed on a SQL 2000 server.

The scrpt looks like this:


---------------------------------------------------------------------------------------------------
USE [master]
GO
IF NOT EXISTS (SELECT * FROM master.dbo.syslogins WHERE loginname = N'SSDBUSERNAME')
EXEC sp_addlogin N'SSDBUSERNAME', N'SSDBPASSWORD'
GO
GRANT ADMINISTER BULK OPERATIONS TO [SSDBUSERNAME]
GO
GRANT AUTHENTICATE SERVER TO [SSDBUSERNAME]
GO
GRANT CONNECT SQL TO [SSDBUSERNAME]
GO
GRANT CONTROL SERVER TO [SSDBUSERNAME]
GO
GRANT CREATE ANY DATABASE TO [SSDBUSERNAME]
GO
USE [master]
GO
If EXISTS (Select * FROM master.dbo.syslogins WHERE loginname = N'SSDBUSERNAME')
ALTER LOGIN [SSDBUSERNAME] WITH PASSWORD=N'SSDBPASSWORD'
GO
GRANT ADMINISTER BULK OPERATIONS TO [SSDBUSERNAME]
GO
GRANT AUTHENTICATE SERVER TO [SSDBUSERNAME]
GO
GRANT CONNECT SQL TO [SSDBUSERNAME]
GO
GRANT CONTROL SERVER TO [SSDBUSERNAME]
GO
GRANT CREATE ANY DATABASE TO [SSDBUSERNAME]
GO
USE [master]
GO
IF EXISTS (select * from dbo.sysdatabases where name = 'ISIZ')
DROP DATABASE [ISIZ]
GO
USE [SurveyData]
GO
exec sp_adduser 'SSDBUSERNAME'
GRANT INSERT, UPDATE, SELECT, DELETE
TO SSDBUSERNAME
GO
USE [SurveyManagement]
GO
exec sp_adduser 'SSDBUSERNAME'
GRANT INSERT, UPDATE, SELECT, DELETE
TO SSDBUSERNAME
---------------------------------------------------------------


I need to be converted to a script that can be executed on both MSSQL 2000 and MSSQL 2005.

I was wondering if somebody there could help me with this problem?!

Thanks,
Ben"

View 1 Replies View Related

Migration MSSQL 2000 32-bit To MSSQL 2005 64-bit

Nov 17, 2007

I've been tasked to move our production databases on MSSQL 2000 to 2005. I've supported MSSQL since version 6.5 and performed migrations to successor versions.

Current Environment is MSSQL 2000 32-bit with current Service Packs.

I've performed mock migrations on Test servers upgrading all Production instances simultaneously from MSSQL 2000 to 2005 32-bit. The Test environment is identical to Production minus server name, IP etc. Also I have a separate server with MSSQL 2005 installed where I use the DETACH / ATTACH and BACKUP / RESTORE method for migration / acceptance testing. There are approximately 30 databases totaling 70 GB. This has gone as expected and fairly successful. Vendors have been coordinated with to update code and staff for acceptance testing.

I'd prefer going directly to MSSQL 2005 64-bit instead if possible due to memory benefits etc. This is where I'd like some feedback prior to borrowing a 64-bit server for testing.

Upgrade options:

1. Is it better to migrate from MSSQL 2000 32-bit to 2005 64-bit via:
a. DETACH / ATTACH
b. BACKUP / RESTORE
c. Is one method more advantageous relating to the end result?
2. Regarding XP clients, have issues been experienced with the default SQL Server driver or is an alternate recommended for XP clients to connect to a MSSQL 64-bit server databases?
3. If you have performed this migration and have relevant experience please pass them along.

View 3 Replies View Related

Deploying MSSQL 2005 Express DB To MSSQL 2005 WKGP Errors

Sep 29, 2006

DB is developed on local computer with MSSQL 2005 Express. My host is on MSSQL 2005 workgroup. Are they compatible, because I am getting errors? Is my approach wrong?

I have tried several approaches.

A) I created a backup of database on my local, then placed a copy on the server. Then I tried to restore through Server Management Studio. I get this error.

TITLE: Microsoft SQL Server Management Studio

------------------------------

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

ADDITIONAL INFORMATION:

The backed-up database has on-disk structure version 611. The server supports version 539 and cannot restore or upgrade this database.

RESTORE FILELIST is terminating abnormally. (Microsoft SQL Server, Error: 3169)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=08.00.2039&EvtSrc=MSSQLServer&EvtID=3169&LinkId=20476

------------------------------

BUTTONS:

OK

------------------------------



B: I also have tried copying the database. I put it in the same path as the other databases that can be read with server management studio on the server. Then, tried to get to it through server managements studio and it did not appear. So I tried to attach it. Then I received this error:

TITLE: Microsoft SQL Server Management Studio

------------------------------

Attach database failed for Server 'MROACH1'. (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476

------------------------------

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

Could not find row in sysindexes for database ID 10, object ID 1, index ID 1. Run DBCC CHECKTABLE on sysindexes.

Could not open new database 'LodgingDB'. CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 602)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=602&LinkId=20476

------------------------------

BUTTONS:

OK

------------------------------

C: I have also tried opening the Database, and back up file through Server Management Studio. without success.

D: I also tried Windows and Software update at microsoft update, but no updates were recommended for Version on Server.

I'm surprised this is so hard. My original data base was created in same family of software. 2005 MS SQL Express. I could use some direct help from someone experienced with this. Am I doing it wrong or are the DB versions incompatible.

Mark Roach





View 5 Replies View Related

Conversion Of MSSql 2000 Database To MSSQL 2005 Database

Jan 18, 2008

How to convert a database in MSSQL 2000 to MSSQL 2005 database.Is there any tool or documentation available for this?

View 3 Replies View Related

GUI Client For MsSQL (was: MSSQL Help)

Sep 25, 2007

I have my MSSQL hosted, any interface i can use so i can't connect to the data source?

for Mysql, i know i can use phpmyadmin, or mysql interface.

i have no idea for MSSQL, any advices?

i know there is one, which is Toad, but it has a lots of limitations, any good idea?

thanks.

View 2 Replies View Related

MsSQL And Php Resources (was: Need Mssql)

Feb 17, 2008

Hi,


till now i have used mysql with php.now i want to use mssql with php.my php and apache versions are
php 5.2.3
apache 2.2.4

from where i can get mssql and what i need to run my php scripts with mssql database.iam newbie in mssql.any of your help will be surely appreciated

thanks
mrjameer

View 2 Replies View Related

Parameterized Queries Running Slower Than Non-parameterized Queries

Jul 20, 2005

HelloWhen I use a PreparedStatement (in jdbc) with the following query:SELECT store_groups_idFROM store_groupsWHERE store_groups_id IS NOT NULLAND type = ?ORDER BY group_nameIt takes a significantly longer time to run (the time it takes forexecuteQuery() to return ) than if I useSELECT store_groups_idFROM store_groupsWHERE store_groups_id IS NOT NULLAND type = 'M'ORDER BY group_nameAfter tracing the problem down, it appears that this is not preciselya java issue, but rather has to do with the underlying cost of runningparameterized queries.When I open up MS Enterprise Manager and type the same query in - italso takes far longer for the parameterized query to run when I usethe version of the query with bind (?) parameters.This only happens when the table in question is large - I am seeingthis behaviour for a table with > 1,000,000 records. It doesn't makesense to me why a parameterized query would run SLOWER than acompletely ad-hoc query when it is supposed to be more efficient.Furthermore, if one were to say that the reason for this behaviour isthat the query is first getting compliled and then the parameters aregetting sent over - thus resulting in a longer percieved executiontime - I would respond that if this were the case then A) it shouldn'tbe any different if it were run against a large or small table B) thisperformance hit should only be experienced the first time that thequery is run C) the performance hit should only be 2x the time for thenon-parameterized query takes to run - the difference in response timeis more like 4-10 times the time it takes for the non parameterizedversion to run!!!Is this a sql-server specific problem or something that would pertainto other databases as well? I there something about the coorect use ofbind parameters that I overall don't understand?If I can provide some hints in Java then this would be great..otherwise, do I need to turn/off certain settings on the databaseitself?If nothing else works, I will have to either find or write a wrapperaround the Statement object that acts like a prepared statement but inreality sends regular Statement objects to the JDBC driver. I wouldthen put some inteligence in the database layer for deciding whetherto use this special -hack- object or a regular prepared statementdepending on the expected overhead. (Obviously this logic would onlybe written in once place.. etc.. IoC.. ) HOWEVER, I would desperatelywant to avoid doing this.Please help :)

View 1 Replies View Related

Migrate MSSQL 2005 Express -&&> MSSQL 2005 Srv

Apr 25, 2006

Hi!

What is the best way to migrate MSSQL 2005 Express -> MSSQL 2005 Srv?

View 4 Replies View Related

Nested SQL(Nested SQL(Nested SQL(Nested SQL)))

Jan 3, 2007

Can you give a whole SQL statement an alias so you can use it later?

Eg.

SELECT * FROM Employees WHERE age < 19
-- Could I call the above statement something like 'statement1' to use below as shown

SELECT * FROM Employees WHERE age < 25 AND NOT IN (statement1)

Soin effect I get a nested statement.
The reason I am asking about aliases is because this would need to be repeated for, E.g. age < 30 Then age < 35 and so on and so forth.

So basically, I just want to alias a qhole SQL statement

Any help would be greatly appreciated - George

View 14 Replies View Related

Nested

Jul 20, 2005

Hi all,I have a query that looks like so:SELECT GLDCT AS [Doc Type], GLDOC AS DocNumber, GLALID ASPerson_NameFROM F0911WHERE (GLAID = '00181913')However by stipulating that GLAID = GLAID I cannot get the person_nameas not all the GLALID fields are filled in. from my reading of thehelpdesk I have a felling that a nested query might be the way to goor a self-join but beyond this I am lost!?Many thanks for any pointers in advance.Sam

View 3 Replies View Related

NESTED IF

Oct 15, 2007

I am trying to do some nested IF ELSE conditions. I get an error saying 'Error near work Begin'. Below is teh query and the variables comes in thru cursor.

Can somebody advise me on this and also let me know the best practices and alternative to this if any.

IF (@CCTable = 'Claiminassoc')
BEGIN
IF ( @ClaimCenterField = 'ClaimID' AND @VALUE ='Claim')
BEGIN
UPDATE dbo.Table SET ColName = 'Y'
WHERE ID = @ID AND CCTable = 'Claiminassoc' AND CCField = 'ClaimID'
AND DWField = 'CatastropheDesignationFlag'
END
END


ELSE IF (@CCTable = 'EmploymentData')
BEGIN
IF (@VALUE ='TRUE')
BEGIN
UPDATE dbo.Table SET ColName = 'Y'
WHERE ID = @ID AND CCTable = 'Claim' AND CCField = 'WagePaymentCont'
END

ELSE IF (@VALUE ='FALSE')
BEGIN
UPDATE dbo.Table SET ColName = 'N'
WHERE ID = @ID AND CCTable = 'Claim' AND CCField = 'WagePaymentCont'
END
END

View 4 Replies View Related

Help With Nested CTE

Apr 2, 2008



Hi gang,

I have a challenge, which seems like it is probably trivial, but SQL chops are not up to the task, and I am hoping one of you hot-shot DBAs can throw me a bone!

I have a query that populates an OLAP Time dimension table (basically one row per day of the year over several years). What I want to do is expand that table to include each hour of each day over the time span.

The CTE I am using for the day population is:



Code Snippet
WITH dates(date)
-- A recursive CTE that produce all dates between 2006 and 2057-12-31
AS
(
SELECT cast('2006' AS dateTime) date -- SQL Server supports the ISO 8601 format so this is an unambigious shortcut for 1999-01-01
UNION ALL -- http://msdn2.microsoft.com/en-us/library/ms190977.aspx
SELECT (date + 1) AS date
FROM dates
WHERE
date < cast('2058' AS dateTime) -1
)






What I wanted to do was something like:


Code Snippet
WITH hours(hr)
AS
(
SELECT (DATEPART(hh,date) hr
UNION ALL
SELECT (hr + 1) AS hr
FROM hours
WHERE hr < 24
)






inserted just after



Code Snippet
FROM dates





in the initial CTE. But from what I have read, it seems as though nested CTEs are not allowed.

Can anyone show me how to do this?

Thanks in advance for ANY insight/input!

Cheers,

Chris

View 5 Replies View Related

Nested IIF

Feb 14, 2008

Greetings -

Can someone pls advise the maximum number of nested IIF statements allowed in a VS 2005 report builder layout textbox expression? I seem to be hitting a wall at about 10, but cannot find verification. In case the limitation is by characters, the full expression would run about 3,500. Any other limitations which may have a bearing?

Tks & B/R

View 1 Replies View Related

SQL Nested IF-ELSE

Feb 2, 2008

Hi all! I have a problem with my stored procedure, What I'm trying to do here is whenever a user tries to register, the stored procedure will check if the username already exists, and if not it'll now check if the email has already been entered into the database then if not the stored procedure will go ahead and insert the values into the database. *If the username already exists it'll return -1, and if the email already exists then return -2.

SELECT Username FROM UserAccount WHERE Username = @UsernameIF @@ROWCOUNT = 0 SELECT Email FROM UserAccount WHERE Email = @Email
IF @@ROWCOUNT = 0 BEGIN


INSERT INTO UserAccount (Username, Password, Email, FirstName, LastName, Gender, BirthDate, Country, State, Zip, AdditionalInfo)
VALUES (@Username, @Password, @Email, @FirstName, @LastName, @Gender, @BirthDate, @Country, @State, @Zip, @AdditionalInfo)
END
ELSE BEGIN

RETURN -2

END
ELSE BEGIN
RETURN -1

END
END

Thanks!

View 3 Replies View Related

Sql Server Nested Set, How?

Nov 8, 2006

Hi, I'm not sure if this is  a good place to ask sql questions, so please bear with me here...I have a table like soid, parentidWhat I'm trying to do is to write a self join where given a random ID, it'll give me the  whole tree of its decendents. (I don't need its parent)so say I have data liek soid     parentid1      null2      13      2when I specificy 1, it'll give me 2 and 3, even though 3 is indirectly related to 1.  when I say 2, it'll just give me 3. Thanks a lot. GREATLY appreicate it.  

View 1 Replies View Related

Nested Views

Oct 16, 2007

When running reports from data, is it faster using nested views approx 4 levels deep, or writing data to a temp tables then running the report?

View 3 Replies View Related

Nested Select

Apr 7, 2008

What's worng, please help? SELECT TTarea,personel,Date FROM person_table WHERE TTarea = (SELECT TTarea FROM TTarea_table WHERE Center='CENTER_office') I have many TTarea and I want to send back from inner SELECT statement but give an error  that  inner select statement don't return many result.I want to return many result and I display many TTarea in the CENTER_office 

View 2 Replies View Related

How Do I Use @@Identity In A Nested SP????

Nov 12, 2003

Hi All,

Im inserting some data into a table and grabbing the new UserID with this statement

SELECT @UserID = @@IDENTITY


I would like to use the @UserID to Execute another SP within the same proc..
..something like this

Exec AnotherSP(@UserId)

But this doesnt seem to be working....Its seems to me that this is a much better approach performance wise rather than returning the UserID to the Business Logic Layer and calling another SP....Im I correct in that assumption....any assistance would be greatly appreciated.

Thanks in advance
AMRITZ

View 2 Replies View Related

Nested Cursor

Jun 12, 2004

I think I am getting an endless loop here... anyone know how to fix it?

***********************

CREATE PROCEDURE TrigSendPreNewIMAlertP2
@REID int

AS

Declare @RRID int
Declare @ITID int
Declare @FS2 int
Declare @FS1 int


Declare crReqRec cursor for
select RRID from RequestRecords where REID = @REID and RRSTatus = 'IA' and APID is not null
open crReqRec
fetch next from crReqRec
into
@RRID



Declare crImpGrp cursor for
select ITID from RequestRecords where RRID = @RRID
open crImpGrp
fetch next from crImgGrp
into
@ITID

while @@fetch_status = 0
select @FS1 = @@Fetch_Status

EXEC TrigSendNewIMAlertP2 @ITID

FETCH NEXT FROM crImpGrp
into
@ITID


close crImpGrp
deallocate crImpGrp



while @@Fetch_Status = 0
select @FS2 = @@Fetch_Status

FETCH NEXT FROM crReqRec
into
@RRID



close crReqRec
deallocate crReqRec
GO

View 1 Replies View Related







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