What's The Accepted Way To Retrieve Records In A SQL Table With Null Values Using A Visual Studio 2005 Table Adapter?

Jan 21, 2008

I'm using an ObjectDataSource in Visual Studio to retrieve records from a SQL Server 2005 database.

 I have a very simple dilemma.  In a table I have fields FirstName, Surname, Address1, Address2, Address3 etc. None of these are mandatory fields.

It is quite common for the user not to enter data in Address2, Address3, so the values are <null> in the SQL table.

In Visual Studio 2005 I have an aspx form where users can pass search parameters to the ObjectDataSource and the results are returned according to the passed in parameters.

The WHERE clause in my Table Adapter is:WHERE (Address1 LIKE @Address1 + '%') AND (Address2 LIKE @Address2 + '%') AND   (Address3 LIKE @Address3 + '%') AND (FirstName LIKE @FirstName + '%') AND (Surname LIKE @Surname + '%')

If, for example, I simply want to search WHERE FirstName LIKE ‘R’, this does not return any results if the value of Address3 is <null>

My query is this: Could someone please show me the best way in Visual Studio 2005 to return records even if one of the Address fields is <null>.

For reference, I have tried: Address3 LIKE @Address3 + '%' OR IS NULLThis does work, however itsimply returns every instance where Address3 is <null>  (accounting for about 95% of the records in the database). Thanks in advance Simon

 

View 9 Replies


ADVERTISEMENT

How To Delete A Table In Visual Studio 2005

Aug 21, 2007

I need to delete a database table from my database. I can not figure out how to do it though. I tried deleting individual columns but go an error message "Drop Failed for column 'TPListHistoryId ' (Microsoft.SqlServer.Smo)

View 6 Replies View Related

Table Adapter Not Allowing Null String

Sep 27, 2007

I have an SP that I call via table adapter. If I do not pass a value in the string field ('eventRef'), the SP never gets called - it appears that the table adapter is filtering it...? I need to be able to count records that have an 'eventRef' = to the one I pass, including null. This works fine if I pass an 'eventRef', but never runs if that parm is empty.


Here is the TA definition


<asp:ObjectDataSource ConvertNullToDBNull="true" ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="ImagesByEventTableAdapters.PagedImagesByEvent" OnSelecting="ObjectDataSource1_Selecting" OnSelected="ObjectDataSource1_Selected">

<SelectParameters>

<asp:QueryStringParameter Name="CategoryID" QueryStringField="CategoryID" Type="Int32" DefaultValue="24"/>

<asp:QueryStringParameter Name="EventID" QueryStringField="EventID" Type="Int32"/>

<asp:QueryStringParameter Name="EventRef" QueryStringField="erf" Type="String"/>

<asp:QueryStringParameter Name="PageIndex" QueryStringField="PageIndex" Type="Int32" DefaultValue="0"/>

<asp:Parameter Name="NumRows" Type="Int32" DefaultValue="16"/>

<asp:Parameter Name="ImageCount" Direction="Output" Type="Int32" DefaultValue="0" />

</SelectParameters>

</asp:ObjectDataSource>



And the SP:


set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER PROCEDURE [dbo].[PagingGetProductsByEvent]

@CategoryID INT,

@EventID INT,

@EventRef CHAR(10)=NULL,

@PageIndex INT,

@NumRows INT,

@ImageCount INT OUTPUT

AS



BEGINdo my stuff....

View 1 Replies View Related

Transact SQL :: Retrieve All Records From Parent Table And Any Records From Child Table

Oct 21, 2015

I am trying to write a query that will retrieve all students of a particular class and also any rows in HomeworkLogLine if they exist (but return null if there is no row). I thought this should be a relatively simple LEFT join but I've tried every possible combination of joins but it's not working.

SELECT
Student.StudentSurname + ', ' + Student.StudentForename AS Fullname,
HomeworkLogLine.HomeworkLogLineTimestamp,
HomeworkLog.HomeworkLogDescription,
ROW_NUMBER() OVER (PARTITION BY HomeworkLogLine.HomeworkLogLineStudentID ORDER BY

[Code] ...

It's only returning two rows (the students where they have a row in the HomeworkLogLine table). 

View 3 Replies View Related

Query To Retrieve The Columns That Are Null In A Table

Oct 31, 2006

Hi,

I need help to build a query that shows me how many columns inside a range on columns are null.
Example: quantity1;quantity2;quantity3;quantity4;quantity5; quantity6;quantity7;

Which columns are null?

Thanks in advance

View 6 Replies View Related

How To Retrieve The Last 5 Records From A SqlServer Table ?

Nov 28, 2007

I want to write a sql Query which retrieves the last (some number ) records form a Table ,
the table specification is like :

Table1
==================================
ID int , <----- is identity And identity seed =1
Title char(50) ,
News nvarchar(100)


its like I want to get the last 5 news form DB ...

View 5 Replies View Related

Can Visual Studio 2005 BI Co-exist With Visual Studio 2003?

Jan 19, 2006

I ask because I'm still looking for the source of interface problems I have in using the SSIS designer.

View 4 Replies View Related

Retrieve Values From Child Table

Feb 2, 2005

Hello there,

I need to get the last value (status) from a child table. I try to simplify the problem with the following example.

Create Table Users
(
UserId int,
Lastname nvarchar(50)
)

Create Table UserStatus
(
UserId int,
Date datetime,
StatusId int
)

Create Table Status
(
StatusId int
Status nvarchar(50)
)

A user will go through all Status one by one. (1) Registered -> (2) In progress -> (3) authorized.
Now I want to know which users are in progress (2) but a simple select statement like:

Select LastName from Users Inner Join Users.UsersId = UserStatus.UserId Where UsersStatus.StatusId = 2

Will not return the wanted records because all authorized Users have been in this status.

I hope you understand the problem and can help me out.

Thx in advance.

Etinuz

View 3 Replies View Related

Retrieve Multiple Values From Table

Jun 30, 2007

i am able to store multiple email ids in table (separated by comma).

now the problem is how do i retrieve those email ids from the table so that i can send mails to those email ids??




thanks
Jaimin

View 2 Replies View Related

Query To Retrieve Records That Sum To A Field In Another Table

May 18, 2012

I really need creating a query that will retreive all records from a table where the dbo.CorpAdv.AcctNum field equals a specific value (for this example "0023"), the TranCode = "R" and the sum of the records, starting with the latest, equals the value of a field in another table (dbo.Master.TotalAdv)

dbo.Master.TotalAdv is numeric (dollar amount) and in this example the value is $1,850.00

dbo.CorpAdv.pID is an integer and unique ID for each record, later records have higher numbers
dbo.CorpAdv.AcctNum is text field
dbo.CorpAdv.AdvAmt is numeric (dollar amounts)

[code]....

View 3 Replies View Related

Retrieve Good Records From A Bad Record Table

May 17, 2006

I have a situation where I need a table if bad items to match to. Forexample, The main table may be as:Table Main:fd_Id INT IDENTITY (1, 1)fd_Type VARCHAR(100)Table Matcher:fd_SubType VARCHAR(20)Table Main might have a records like:1 | "This is some full amount of text"2 | "Here is half amount of text"3 | "Some more with a catch word"Table Matcher:"full""catch"I need to only get the records from the main table that do not haveanything in the match table. This should return only record 2.

View 1 Replies View Related

Truncate MS Access Table From Visual Studio Using Code

Dec 24, 2014

I am building a Visual Sudio process that will Truncate and load data to an Access database (2010) from SQL Server (2012). I have one "Execute SQL Task" for one table (LungCancer_HF_Patients):

"DELETE LungCancer_HF_Patients.* FROM LungCancer_HF_Patients;" that parses and works.

I have another table (Report1):

"DELETE Report1.* FROM Report1;"

that does not parse with a message "The query failed to parse. Incorrect syntax near '*'."

Why the first one parses correctly and the other one does not?

View 2 Replies View Related

Transact SQL :: Retrieve Values Instead Of Joining To Same Table 5x

Jun 2, 2015

I have a table (can't change the schema of it since it is part of an off the shelf app ) that has columns for individuals which I need to extract several pieces of information, essentially Phone, Email Address, etc.  See U1 - U6

What is a better way to return this information rather than multiple joins?

Select
[AccountNumber]
,a.[AccountId]
,[Name]
,[new_LocationID]
,[ws_name]
,[new_BillingManageruserName]
,[new_AreaServiceManName]

[Code] ....

View 3 Replies View Related

Retrieve A Recordset From One Table Based On The CSV Values In The Field Of Another

Feb 6, 2007

Hello!

I have 2 tables, one that contains a set of codes and their definitions, and another where each record has a field that contains several of these codes separated by commas:

Tab1

SubCode | Definition
---------------
S100 | Def of S100
S101 | Def of S101
S102 | Def of S102

Tab2

DepID | Purpcode |SubCodes
-----------------------------
1 | P100 | S100,S101,S102
1 | P101 | S100, S101
2 | P101 | S100,S102

I'm trying to create a query against Tab1 so that it retrieves a recordset of Subcodes and definitions based on the contents of the Subcodes field for a record in Tab2. I've tried this using a subquery, as follows:

SELECT SubCode ,Definition
FROM Tab1
WHERE SubjectCode IN
(SELECT CHAR(39) + REPLACE(SubjectCodes, CHAR(44), CHAR(39 + CHAR(44)+ CHAR(39)) + CHAR(39)
FROM Tab2
WHERE DepID = 1 AND PurposeCode = 'P101')

The subquery will return: 'S100','S101' and I expect the final recordset to be:

SubCode | Definition
---------------
S100 | Def of S100
S101 | Def of S101

However, it's not returning any records. If I execute the subquery separately and then plug its results into the main query e.g.

SELECT SubCode ,Definition
FROM Tab1
WHERE SubjectCode IN ('S100','S101')

it returns the expected recordset. Does anyone have any pointers? It's driving me nuts..

Cheers
Greg

Complete DDL, Sample Data, and Query below:


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SubjectCodeDefinition]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[SubjectCodeDefinition]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DepartmentReturn]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[DepartmentReturn]
GO

CREATE TABLE [dbo].[SubjectCodeDefinition] (
[SubjectCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Definition] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DepartmentReturn] (
[DeptID] [int] NULL ,
[PurposeCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SubjectCodes] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
) ON [PRIMARY]
GO

INSERT INTO SubjectCodeDefinition(SubjectCode, Definition)
SELECT 'S100', 'Definition of Code S100' UNION ALL
SELECT 'S101', 'Definition of Code S101' UNION ALL
SELECT 'S102', 'Definition of Code S102' UNION ALL
SELECT 'S103', 'Definition of Code S103' UNION ALL
SELECT 'S104', 'Definition of Code S104' UNION ALL
SELECT 'S105', 'Definition of Code S105'
GO

INSERT INTO DepartmentReturn(DeptID,PurposeCode,SubjectCodes)
SELECT 1,'P100','S100,S101,S104' UNION ALL
SELECT 1,'P101','S102,S103' UNION ALL
SELECT 1,'P102','S100,S101,S105' UNION ALL
SELECT 2,'P100','S100,S101,S104,S105' UNION ALL
SELECT 2,'P103','S103,S104,S105' UNION ALL
SELECT 3,'P100','S100,S102,S104'
GO

SELECT SubjectCode ,Definition
FROM SubjectCodeDefinition
WHERE SubjectCode IN
(SELECT CHAR(39) + REPLACE(SubjectCodes, CHAR(44), CHAR(39)+ CHAR(44)+ CHAR(39)) + CHAR(39)
FROM DepartmentReturn
WHERE DeptID = 1 AND PurposeCode = 'P102')

View 1 Replies View Related

Error Inserting Image Into SQL Server2000 Table From Pocket PC Application Only When Using Stored Procedure In Table Adapter Wiz

Apr 24, 2008

My Pocket PC application exports signature as an image. Everything is fine when choose Use SQL statements in TableAdapter Configuration Wizard.


main.ds.MailsSignature.Clear();

main.ds.MailsSignature.AcceptChanges();


string[] signFiles = Directory.GetFiles(Settings.signDirectory);


foreach (string signFile in signFiles)

{


mailsSignatureRow = main.ds.MailsSignature.NewMailsSignatureRow();

mailsSignatureRow.Singnature = GetImageBytes(signFile); //return byte[] array of the image.

main.ds.MailsSignature.Rows.Add(mailsSignatureRow);

}


mailsSignatureTableAdapter.Update(main.ds.MailsSignature);

But now I am getting error "General Network Error. Check your network documentation" after specifying Use existing stored procedure in TableAdpater Configuration Wizard.


ALTER PROCEDURE dbo.Insert_MailSignature( @Singnature image )

AS

SET NOCOUNT OFF;

INSERT INTO MailsSignature (Singnature) VALUES (@Singnature);



SELECT Id, Singnature FROM MailsSignature WHERE (Id = SCOPE_IDENTITY())

For testing I created a desktop application and found that the same Code, same(Use existing stored procedure in TableAdpater Configuration Wizard) and same stored procedure is working fine in inserting image into the table.

Is there any limitation in CF?

Regards,
Professor Corrie.

View 3 Replies View Related

How Can I Copy The Content Of MS Access Table In Database SQL Using Visual Studio Basic

Sep 26, 2007

Code Snippet

Hi there,

I'm struggeling for more than a week now with this problem, without a finding the solution.

I have two databases, MS Access and SQL Server 2005 Express Edition

Using a procedure in Visual Studio i would like to copy all the records from one table in MS Access into an existing table in SQL Server (the tables have the same name and the same layout)

I tried to prepare one Dataset to copy from Access into SQL Server but when i run the command 'DaSQL.Update(DsSQL, "Tabella") nothing happens (not even an exeption has been raised), looking during debug, the DataSet seems filled though...

Please could anyone explain what's wrong and / or is there a more quicker way to copy data from a table to another?


Note i woul have as a final goal to get data from an AS400 database by ODBC, manage it, and put it on SQL Server for a 'data mining' scope (eliminating the use of MS Access, not suited for FE-BE).

the procedure goes like this;


' Create a connection to the MS Access Database
Dim connectionToAccess As New OleDbConnection(DBConnectionAccString)
strsql = "SELECT * FROM [TABELLA]"
connectionToAccess.Open()
Dim DaAccess As New OleDbDataAdapter(strsql, connectionToAccess)

Dim DsAccess As New DataSet("ACCESS")
DaAccess.FillSchema(DsAccess, SchemaType.Source, "Tabella")
DaAccess.Fill(DsAccess, "Tabella")

' Create a connection to the SQL Database
Dim connectionToSQL As New SqlConnection(DBConnectionSQLString)
connectionToSQL.Open()
Dim DaSQL As New SqlDataAdapter(strsql, connectionToSQL)

Dim DsSQL As New DataSet("SQL")
DaSQL.FillSchema(DsSQL, SchemaType.Source, "Tabella")
DaSQL.Fill(DsAccess, "Tabella")

DaSQL.Update(DsSQL, "Tabella")

Note I tried also the following, withou a result;


DsSQL = DsAccess.Copy
DaSQL.Update(DsSQL, "Tabella")

Please is there someone who could respond !!???

View 6 Replies View Related

Visual Studio Closes When Accessing The Columns Tab Of A Lookup Transformation Referencing SQL 7 Table

Jul 30, 2007

I'm creating a new Integration Services Project that copies data out of a SQL 7 server, transforms it, and places the data on a SQL 2005 (SP 2) Server. When defining a lookup transformation, if I specify an OLE DB Connection to my server running SQL 7 as the reference table, as soon as I click on the Colums tab, Visual Studio closes / crashes and dumps me to windows. I don't get an error message. If however I specify a connection to a server running SQL 8, or SQL 2005, no problems.

Is this supposed to happen?

My workstation is running Windows XP Pro SP2, Visual Studio 2005 Pro.

Microsoft SQL Server Integration Services Designer
Version 9.00.1399.00

The server that doesn't work for a reference table is running Windows 2000 Server SP4
SQL 7.00.623


Thanks for your help,
Kirk

View 6 Replies View Related

Table Visibility Not Functioning Correctly On Server, Works Fine In Visual Studio

Feb 13, 2007

I have a report problem. I'm using a parameter to dynamically control visibility for two tables. If the parameter is set to one value, I want to switch one of the tables to invisible, if the parameter is set to another, I want the other table to be invisible instead.

This all works fine in Visual Studio. When I publish it to my report server, the visibility controls no longer function and both tables always display. Any ideas here?

I'm running 2005, SP2 CTP.

View 4 Replies View Related

Retrieve NULL Values From Config File

Apr 10, 2008

Hi,

my configuration file provides parameters that are used for an SQL query in my package. However, for these parameters it must be possible to pass NULL to the query.

This seems to be impossible in SSIS..? If the config file provides no value, the package uses a default value - and this default value can not be null.

Any suggestions?

Thanks a lot,

Regards
Jan

View 4 Replies View Related

SQL Server 2005 - Studio Express Vs. Visual Studio 2005 Install

May 5, 2006

I'm very confused.  I installed Visual Studio 2005 and thought I understood that SQL Server 2005 came with it, but it appears that it's SQL Server 2005 - Express.  Can anyone tell me what I need to do in order to get Data Transformation Services loaded or the equivalent of DTS in SQL Express? 
 
 

View 1 Replies View Related

Query For Findign NULL Records In Table

Jan 10, 2008

Can someone helo me to query a table and list all the columns and how many null records are there in each.

View 3 Replies View Related

MS Visual Studio 2005 Vs SQL Server Business Intelligence Development Studio

Apr 16, 2007

I recently installed the Evaluation Edition of SQL Server 2005 x64 and it appears that MS Visual Studio 2005 is installed in stead of SQL Server Business Intelligence Development Studio. When I choose new project the only template available is "Blank Solution". How do I get all the templates (i.e. Analysis Server Project, Integration Services Project, Report Model Project, Report Server Wizard project, etc.)?

Or would it be better to uninstall MS Visual Studio 2005 and attempt to reinstall BIDS?



View 4 Replies View Related

Visual Studio C# Finding Records On A SQL Database

Jul 9, 2007

I need to find the name of the user that signed in to the web page.  For this, I have a web page with a text box, the program should access a SQL database use, use the userID and return the name.  My code (working) does the following:string mySqlQuery = "";
string strCnn = "";SqlDataReader myDataReader = null;
mySqlQuery = "SELECT c_name FROM database WHERE c_user='demo'";
//connect to the databasestrCnn = "Data Source=" + connectionServer + "; Initial Catalog=" + connectionDatabase + "; user id=" + connectionUserID + "; password=" + connectionPassword + "; Integrated Security=false";cnn = new SqlConnection(strCnn);
 
try
{
cnn.Open();MessageBox.Show("Success Opening the Database");
}
catch
{MessageBox.Show("Problems with the database");
}SqlCommand sqlSelectCommand = new SqlCommand(mySqlQuery, cnn);
 
 tbName.Text = "me";
cnn.Close();
 
This works, I just need to retrieve the value of c_name.  Any help, thanks

View 2 Replies View Related

Alter Table Datatype With Null Values

May 7, 2015

I am trying to change a column from a decimal(18,2) to a decimal(18,3). What is the SQL command to alter this table?

SQL Command:

alter table TableName
alter column ColumnName decimal(18,3) [null]

the above command is right ?

View 6 Replies View Related

Can't Import An Access Table Due To Null Values.

Jul 20, 2005

Question: Why would I not be able to import an Access 97 table inwhich some records have null values in fields that allow null values?Wouldn't the table's design be imported first, bringing the columns'"allow nulls" attribute with it?I'm dealing with both text and numeric columns. Not all columnscontaining nulls cause an error.Thanks,Bob C.

View 2 Replies View Related

.NET Framework :: CLR Table Function With Null Values

Jun 23, 2015

I'm trying to do a Clr function wiht null values but I have an error. My Clr is like this:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Text;

[code]...

A .NET Framework error occurred during execution of user-defined routine or aggregate "function":

System.InvalidCastException: La conversión especificada no es válida.
System.InvalidCastException:
   en Microsoft.SqlServer.Server.ValueUtilsSmi.GetSqlInt16(SmiEventSink_Default sink, ITypedGettersV3 getters, Int32 ordinal, SmiMetaData metaData)
   en UserDefinedFunctions.function()

View 5 Replies View Related

Displaying NULL Values In The Destination Table

Sep 17, 2007



Dear Members,

I extracted data from a flat file using SSIS package and load them into destination table. One column contains no data. Data type of that column is varchar(9). I want to display "NULL" values in that column.

I used LOOK up transformation and used the following query.


SELECT PassThroughRouting =
CASE PassThroughRouting
WHEN 'NULL' THEN 'NULL'
END
FROM EPICWareTable

But it gives a error message.

Does any body can help me?

Thanks

View 9 Replies View Related

Filtering Out Null Values On A Matrix Table

Jan 29, 2008

Hi,

How do I filter out Null values in a matrix table

one off my columns is picking up the Null values and I would like to filter this out.

Is there a simple way of doing this as filtering it out at the Dataset level is not the ideal solution for me.

thanks

View 5 Replies View Related

Visual Studio 2005 Standard And SQL Server Management Studio?

Sep 4, 2007

I am new to visual studio and I am still not sure of all its components and features.

I installed visual studio 2005 standard edition but cannot find SQL Server Management Studio?

I guess this must be because it is not included with Visual studio 2005 standard. Is it included with VS 2005 professional?

I want to add pictures of products to my shopping site using an SQL database and I’ve been told that SQL Server Management studio is required as it is a graphical tool.

How would I go about obtaining the SQL server management studio. There seems to be different versions of SQL server that it is confusing to know which one to purchase.

Will the SQL server 2005 version that comes with Visual studio standard be sufficient for me now right? I want to create a shopping site with hundreds, perhaps even thousands of products. I want to use an SQL server 2005 database. The database will include ‘dynamically generated’ product images if that is the correct terminology.

My goodness, it seems I still have so much to learn.

Thanks

View 1 Replies View Related

Need Help Managing NULL Values In SQL - Visual Web Developer

Feb 18, 2008

Hi to all and thanks in advance.
I´m newbie with SQL Server & VWD Studio, and I´m trying to develop a little web application.
The issue is that my application can´t upgrade the DB fields if you introduce a NULL value.
When I created the table, I denied the NULL value introduction. I cant insert NULL values using the SQL Server Management Studio, but I can introduce these values using code.
Do someone have any suggestion to hadle properly this issue ?

B/R

View 4 Replies View Related

1) Null Value In Foreign Key 2) Extra Value To Indicate All The Values In PK Table Apply

Feb 27, 2007

I have two tables  1) tblCustomer (ID, Name, City)  2) tblemp (ID, NAME, Dept.ID, tblcustomer.ID)
Both the tables have ID as PKA emp can be either assigned a) All customers b)single customer c) NO customer
Pls note:- there will never be 2 or 3 customer linked to emp (my actuall requirement tables are different but to explain i am using the above tables)
I know how to assign single customer......but had problem how to link all customers and "no customer"
Please tell me if the following solution is right?1) I will manually insert a record in tblCustomer with id 0 as " all customers" and will not allow the user to delete it 2) store null in FK if it is "no customer"
Also please tell me is it ok to store one more value in tblCustomer as -1 and take it as "No customer"
I have a DDL in the Employee page which should be displaying the names of allthe customers with 2 extra values "ALL CUSTOMERS" and "SELECT"  Select is the default value in DDL which says "NO CUSTOMER" selected yet
Thank youSara

View 10 Replies View Related

T-SQL (SS2K8) :: Find Null Values Between 3 Datasets In One Table

Mar 21, 2014

I have a table with data in two columns, item and system. I am trying to accomplish is we want to compare if an item exists in 1, 2 or all systems. If it exists, show item under that system's column, and display NULL in the other columns.

I have aSQL Fiddle that will allow you to visualize the schema.

The closest I've come to solving this is a SQL pivot, however, this is dependent on me knowing the name of the items, which I won't in a real life scenario.

select [system 1], [system 2], [system 3]
from
(
SELECT distinct system, item FROM test
where item = 'item 1'
) x
pivot
(
max(item)

[Code]...

View 2 Replies View Related

Inserting Few Recordsets Into Temp Table Containing NULL Values

Jul 20, 2005

HiI need some help on achieving the following:I wrote a querie which collects Data out of three Tables, the Resultlooks like this:SET NOCOUNT ONDECLARE @ROWINTDECLARE @CURPTNO CURSORSET @CURPTNO = CURSORFORSELECT * FROM TEMPOPEN @CURPTNOFETCH NEXT FROM @CURPTNOINTO @ROWWHILE (@@FETCH_STATUS = 0)BEGINSELECT ONE.CYNO, ONE.ROLE, ONE.ROL_BEZ, ONE.PTNO, ONE.NOCY, TWO.TEXTAS NOCY_TEXTFROM(SELECT CY.CYNO,RE.CYNO AS RECYNO, RTRIM(RE.ROLE) AS ROLE, RTRIM(V_ROLE.TEXT) ASROL_BEZ,RE.PTNO AS PTNO, RTRIM(RE.NAME) AS SACHBEARBEITER, RE.NOCYFROM CYRIGHT OUTER JOINRE ON RE.CYNO = CY.CYNOINNER JOINV_ROLE ON RE.ROLE = V_ROLE.CODEWHERE (RE.PTNO IN(SELECT PT.PTNOFROM PTWHERE PT.PTNO IN(@ROW)AND V_ROLE.LANGUAGE = PT.CLANG))) AS ONELEFT JOIN(SELECT V_NOCY.CODE, V_NOCY.TEXTFROM V_NOCYINNER JOINPT ON PT.CLANG = V_NOCY.LANGUAGEAND PT.PTNO IN (SELECT PT.PTNOFROM PTWHERE PT.PTNO IN(@ROW))) AS TWOON ONE.NOCY = TWO.CODEFETCH NEXT FROM @CURPTNOINTO @ROWENDCLOSE @CURPTNODEALLOCATE @CURPTNOThe Result looks like this:RS1:6313,1300,Architekt,99737505,NULL,NULL2392762,100,Bauherr,99737505,NULL,NULLRS2:2693265,100,Bauherr,99756900,NULL,NULLNULL,1,Planer,99756900,2,Bauherr macht Pläne selberRS3:2691919,100,Bauherr,99755058,NULL,NULL2691962,6000,Kontakt,99755058,NULL,NULLMy Problem is, that I need to have all the Resultsets in one Table atthe end.So my further undertaking was to create a Temp Table with theexpectation to receive all the resultsets in one Step.The TSQL for this looks like that:SET NOCOUNT ONCREATE TABLE #CYRE_TEMP(CYNOINT NULL,ROLEINT NULL,ROL_BEZVARCHAR (60) NULL,PTNOINT NULL ,NOCYINT NULL,TEXTVARCHAR (60) NULL)GODECLARE @CYNOINT,@ROLEINT,@ROL_BEZVARCHAR (60),@PTNOINT,@NOCYINT,@TEXTVARCHAR (60),@ROWINT,@CURPTNOCURSORSET @CURPTNO = CURSOR FORSELECT PTNO FROM TEMPOPEN @CURPTNOFETCH NEXT FROM @CURPTNOINTO @ROWWHILE (@@FETCH_STATUS = 0)BEGININSERT INTO #CYRE_TEMP (CYNO, ROLE, ROL_BEZ, PTNO, NOCY, TEXT)VALUES(@CYNO,@ROLE ,@ROL_BEZ ,@PTNO ,@NOCY ,@TEXT)SELECT @CYNO = ONE.CYNO,@ROLE = ONE.ROLE,@ROL_BEZ = ONE.ROL_BEZ,@PTNO = ONE.PTNO,@NOCY = ONE.NOCY,@TEXT = TWO.TEXTFROM(SELECT CY.CYNO, RTRIM(RE.ROLE) AS ROLE, RTRIM(V_ROLE.TEXT) ASROL_BEZ,RE.PTNO AS PTNO, RTRIM(RE.NAME) AS SACHBEARBEITER, RE.NOCYFROM CYRIGHT OUTER JOINRE ON RE.CYNO = CY.CYNOINNER JOINV_ROLE ON RE.ROLE = V_ROLE.CODEWHERE (RE.PTNO IN(SELECT PT.PTNOFROM PTWHERE PT.PTNO =@ROWAND V_ROLE.LANGUAGE = PT.CLANG))) AS ONELEFT JOIN(SELECT V_NOCY.CODE, V_NOCY.TEXTFROM V_NOCYINNER JOINPT ON PT.CLANG = V_NOCY.LANGUAGEAND PT.PTNO IN (SELECT PT.PTNOFROM PTWHERE PT.PTNO =@ROW)) AS TWOON ONE.NOCY = TWO.CODEFETCH NEXT FROM @CURPTNOINTO @ROWENDCLOSE @CURPTNODEALLOCATE @CURPTNOSELECT * FROM #CYRE_TEMPDROP TABLE #CYRE_TEMPGOAnd the Output looks like this now:Q1:NULL,NULL,NULL,NULL,NULL,NULL2392762,100,Bauherr,99737505,NULL,NULLNULL,1,Planer,99756900,2,Bauherr macht Pläne selberCan someone help me getting all the 6 Rows into one Table as Output?I appreciate any available Help on this..Ssscha

View 1 Replies View Related







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