Rows Flattened To Concatenated String

Jun 20, 2008

I have a table with multiple rows for a single reference, e.g.

Col1 Col2
1 John
1 Mary
1 Tom
2 Dick
2 Anne

How do I create this view:

Col1 Col2
1 John, Mary, Tom
2 Dick, Anne

View 5 Replies


ADVERTISEMENT

Nulls In Concatenated String

Sep 23, 2005

How do I prevent the following null 'Answer'?This SQL will return a null string for 'Answer' whenever the count is null either for 'subquery-1' or for 'subquery-2', even though the other is not null. I need a string in either case. It would be better to have 'Answer' be "f1=, f2=25" than to have nothing. It doesn't seem right that both COUNT's have to be non-null to get anything other than null for the concatenated 'Answer'. There ought to be a way for COUNT to return 0 in some cases where it now returns null. I'd expect/prefer an 'Answer' of "f1=0, f2=25" or maybe even "f1=<null>, f2=25".I expect I'd have the same problem with nulls even if I wasn't using subqueries.SELECT 'f1='+CAST(COUNT(subquery-1) AS VARCHAR)+', f2='+CAST(COUNT(subquery-2) AS VARCHAR) AS AnswerFROM table1WHERE condition=5GROUP BY fieldX

View 1 Replies View Related

How To Do Separate The Concatenated String

Oct 5, 2007

declare @filter varchar(100)
set @filter = '10,''firststring''||10,''secondstring'''
declare @tbl table
(id decimal,
name varchar(20))

insert into @tbl values (substring(@filter,0,patindex('%||%',@filter)))


hai in the above exmaple, i recieve input value (@filter) as concated string . pipeline(||) is my delimiter..
i want to split the string based on this delimater and need to insert into @tbl..

There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.


What is the error in this. i believe i can do this way to insert to concatinated values.
Help pls

View 6 Replies View Related

Concatenated String For Each Row In A Query...

Mar 31, 2008

So I've run into another problem. I've figured out how to concatenate multiple rows into a single string my only problem is using that on another query with multiple rows...Basically what I'm trying to do is pull up information for each class a student has in his/her profile and while at it pull up any prerequisite classes that are associated with a certain class. So the final query would look something like this...

StudClassID Completed Class ID Name Description Credits Prereq... rest are insignificant...
0 0 CSC200 Cool prog... blah.... 3 CSC160, CSC180

I get the concept of the coalesce and cast just i'm not understanding how to get it to work with each return on the main select...anyways below are the tables and my current query call...




Code Snippet




USE [C:PROGRAM FILESMICROSOFT SQL SERVERMSSQL.1MSSQLDATACOLLEGE.MDF]
GO
/****** Object: Table [dbo].[Student_Classes] Script Date: 03/31/2008 01:32:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Student_Classes](
[StudClassID] [int] IDENTITY(0,1) NOT NULL,
[StudentID] [int] NULL,
[ClassID] [varchar](7) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreditID] [int] NULL,
[Days] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Time] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Classroom] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Grade] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Semester] [varchar](40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Notes] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Completed] [tinyint] NULL CONSTRAINT [DF_Student_Classes_Completed] DEFAULT ((0)),
CONSTRAINT [PK_Student_Classes] PRIMARY KEY CLUSTERED
(
[StudClassID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Student_Classes] WITH CHECK ADD CONSTRAINT [FK_Student_Classes_ClassID] FOREIGN KEY([ClassID])
REFERENCES [dbo].[Classes] ([ClassID])
GO
ALTER TABLE [dbo].[Student_Classes] CHECK CONSTRAINT [FK_Student_Classes_ClassID]
GO
ALTER TABLE [dbo].[Student_Classes] WITH CHECK ADD CONSTRAINT [FK_Student_Classes_CreditID] FOREIGN KEY([CreditID])
REFERENCES [dbo].[Credits] ([CreditID])
GO
ALTER TABLE [dbo].[Student_Classes] CHECK CONSTRAINT [FK_Student_Classes_CreditID]
GO
ALTER TABLE [dbo].[Student_Classes] WITH CHECK ADD CONSTRAINT [FK_Student_Classes_StudentsID] FOREIGN KEY([StudentID])
REFERENCES [dbo].[Students] ([StudentID])
GO
ALTER TABLE [dbo].[Student_Classes] CHECK CONSTRAINT [FK_Student_Classes_StudentsID]

USE [C:PROGRAM FILESMICROSOFT SQL SERVERMSSQL.1MSSQLDATACOLLEGE.MDF]
GO
/****** Object: Table [dbo].[Prerequisites] Script Date: 03/31/2008 01:32:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Prerequisites](
[PrerequisiteID] [varchar](7) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ClassID] [varchar](7) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
CONSTRAINT [PK_Prerequisite] PRIMARY KEY CLUSTERED
(
[PrerequisiteID] ASC,
[ClassID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Prerequisites] WITH CHECK ADD CONSTRAINT [FK_Prerequisite_ClassID] FOREIGN KEY([ClassID])
REFERENCES [dbo].[Classes] ([ClassID])
GO
ALTER TABLE [dbo].[Prerequisites] CHECK CONSTRAINT [FK_Prerequisite_ClassID]
GO
ALTER TABLE [dbo].[Prerequisites] WITH CHECK ADD CONSTRAINT [FK_Prerequisite_Prereq] FOREIGN KEY([PrerequisiteID])
REFERENCES [dbo].[Classes] ([ClassID])
GO
ALTER TABLE [dbo].[Prerequisites] CHECK CONSTRAINT [FK_Prerequisite_Prereq]

USE [C:PROGRAM FILESMICROSOFT SQL SERVERMSSQL.1MSSQLDATACOLLEGE.MDF]
GO
/****** Object: Table [dbo].[Credits] Script Date: 03/31/2008 01:32:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Credits](
[CreditID] [int] IDENTITY(0,1) NOT NULL,
[ClassID] [varchar](7) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Credits] [tinyint] NULL,
CONSTRAINT [PK_Credits] PRIMARY KEY CLUSTERED
(
[CreditID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Credits] WITH CHECK ADD CONSTRAINT [FK_Credits_ClassID] FOREIGN KEY([ClassID])
REFERENCES [dbo].[Classes] ([ClassID])
GO
ALTER TABLE [dbo].[Credits] CHECK CONSTRAINT [FK_Credits_ClassID]

SELECT sClass.StudClassID
,sClass.Completed
,sClass.ClassID AS 'Class ID'
,c.LongName AS 'Name'
,c.Description
,cred.Credits
,(SELECT COALESCE(@prerequisites + ', ', '') + CAST(PrerequisiteID AS varchar(7))) AS 'Prerequisites'
,sClass.Grade
,sClass.Days
,sClass.Time
,sClass.Classroom
,sClass.Semester
,sClass.Notes
FROM Student_Classes sClass
INNER JOIN Prerequisites preq
ON preq.ClassID = sClass.ClassID
INNER JOIN Classes c
ON c.ClassID = sClass.ClassID
INNER JOIN Credits cred
ON cred.CreditID = sClass.CreditID
WHERE sClass.StudentID = 0
ORDER BY sClass.ClassID ASC

View 5 Replies View Related

Pass Concatenated String To SPROC

Jul 24, 2004

Hello,

We are creating an app to search through products. On the presentation layer, we allow a user to 'select' categories (up to 10 check boxes). When we get the selected check boxes, we create a concatenated string with the values.

My question is: when I pass the concatenated string to the SPROC, how would I write a select statement that would search through the category field, and find the values in the concatenated string?

Will I have to create Dynamic SQL to do this?...or... can I do something like this...




@ConcatenatedString --eg. 1,2,3,4,5,6,7

SELECT col1, col2, col3 FROM TABLE WHERE CategoryId LIKE @ConcatenatedString



Thanks for your help.

View 2 Replies View Related

Complex Concatenated String For An &#39;exec(@sql) &#39;

Aug 10, 2000

I have:

<<Select @SQL = 'Select Keyword, SICCode From zlk_SICCodeKeyword Where Keyword like ''%' + @KeywordOrSIC + '%''' + ' order by Keyword'

exec(@SQL)>>
which works fine, but I want to modify it to do this

<<Select Replace(Keyword,',',' ') AS Keyword, SICCode From zlk_SICCodeKeyword Where Keyword like 'real%' order by Keyword >>

which works from the query window but I can not get the right combination around the 'replace section' to make up a string for the exec.

All help greatly appreciated
Judith

View 1 Replies View Related

Setting Default Value (concatenated String) Of Column Using UDF

Oct 23, 2005

Hello,

I'm trying to set the default value of a column (SysInvNum) in a table (caseform) of mine by concatenating 3 other fields in the same table. These other fields are all Integer datatypes. they are "CaseYear" e.g. (2005), "InvNum" e.g. (0001) and "PostId" e.g. (5).

So basically the SysInvNum column for this row should read '200500015'

When I run a basic query using the CAST or CONVERT functions like this:

SELECT convert (varchar,caseyear) + convert(varchar,InvNum) + convert(varchar,postid) from caseform

OR

SELECT cast(caseyear as varchar(4)) + cast(InvNum as varchar(4)) + cast(postid as varchar(1)) from caseform

I get the results I want. But since I want this value to be the default value of the column, I tried inserting this: convert (varchar,caseyear) + convert(varchar,InvNum) + convert(varchar,postid) into the default value parameter of the column in the caseform table. The result is a string that is the query itself.

I then tried creating a UDF called getsysinvnum() where I declare and set 2 variables whilst returning one of the variables as a varchar. An example of what it looks like is this:


CREATE FUNCTION GetSysInvNum()
RETURNS varchar
AS
BEGIN
DECLARE @maxcaseid Int
DECLARE @sysinvnum varchar

SELECT @maxcaseid = max (caseid) from caseform
SELECT @sysinvnum = cast(caseyear as varchar(4)) + cast(invnum as varchar(4)) + cast(postid as varchar(1)) from caseform where caseid = @maxcaseid
RETURN @sysinvnum
END


The result I get when I plug this into the default value of the column as : ([dbo].[getsysinvnum]()) is "2".

Yes it returns the number "2" could someone please tell me what I am doing wrong, or suggest a better way for me to do this?

Thanks in advance

'Wale

View 10 Replies View Related

Displaying Multiple Values In A Concatenated String

Oct 17, 2007

SQL Server 2005.(SP2). MS SSRS;
I want to display some numbers in the same line as a concatenated string. For example a Customer may have multiple bills. These bill numbers are displayed in separate rows. I want to display them all on the same line.
Example of current display:
Customer Bill #
ABC Company 123
ABC Company 456
ABC Company 789 etc

I want this to display as below:
Cusotmer Bill #
ABC Company 123, 456, 789, etc.

Is this possible in SSRS. Please help me with the syntax.

Thanks in advance.

View 2 Replies View Related

Error Passing Concatenated String To Proc

Nov 8, 2007

Hi,

I have a stored proc which accepts a varchar(255) as a parameter and when I call the proc using a concatenised string I get an error i.e.

-- Proc
CREATE PROCEDURE #proc_param_test
@p_param1 varchar(40) = NULL
, @p_param2 varchar(40) = NULL
AS
BEGIN
SELECT @p_param1, @p_param2
END

EXEC #proc_param_test 'test', 'test 2'
returns
---------------------------------------- ----------------------------------------
test test 2

but EXEC #proc_param_test 'test', 'test 2' + ' - the rest'

gives a Incorrect syntax near '+'. error

The solution must be a real doddle but it's a 'mare to find anywhere.

Cheers,
John

View 4 Replies View Related

Concatenated String Of Comma Separated Values (was Help With Query)

Nov 21, 2006

I have following 2 queries which return different results.


declare @accountIdListTemp varchar(max)
SELECT COALESCE(@accountIdListTemp + ',','') + CONVERT(VARCHAR(10),acct_id)
FROM (SELECT Distinct acct_id
FROM SomeTable) Result
print @accountIdListTemp



The above query return the values without concatenating it.


declare @pot_commaSeperatedList varchar(max)

SELECT DISTINCT acct_id
into #accountIdListTemp
FROM SomeTable


SELECT @pot_commaSeperatedList = COALESCE(@pot_commaSeperatedList + ',','') + CONVERT(VARCHAR(100),acct_id)
FROM #accountIdListTemp
print @pot_commaSeperatedList
drop table #accountIdListTemp



This query returns result as concatenated string of comma separated values.

If i want to get similar result in a single query how can i get it?

View 4 Replies View Related

Query For A Flattened Result

May 7, 2006

This is how my table was structured:


Code:

=================================================
|id|cat|amount|
|---------------|---------------|---------------|
|1|1|400|
|1|2|150|
|2|1|600|
-------------------------------------------------


I want to query for a result that would look like this:


Code:

=================================================
|id|cat1|cat2|
|---------------|---------------|---------------|
|1|400 |150|
|2|600||
-------------------------------------------------


How do I do it? I'm working with SQL Server 2000.

-Pornsak

View 2 Replies View Related

1:m Database Relation Flattened For Reporting Purposes

Jul 20, 2005

--Example Schema posted at end of message:---For reporting purposes, I need to build a single comma delimited string ofvalues from the "many" tableof a database.The easiest way to see what I want is to look at the sample after mysignature.By the way, this is actually a busines problem, not homework! I justcreated a simpleexample using class and persons because everyone is familiar with thatrelationship.I have two tables on the 'one' side of the relationship: PERSON and CLASSThe ENROLLMENT table resolves the many to many relationship between PERSONand CLASS.(I know that a real system would be date effective, etc, but this is just asimple example.that will show my problem). ENROLLMENT has one row for each Class in which aPerson is enrolled.Look at the sample report: I have to "flatten" the join result and listthe class titles in acomma delimited string. I am stuck with this reporting requirement, and Iam NOT going to denormalizethe tables.One way to accomplish the result is to use a cursor to step through the rowsand build a "Classes"string with concatenation. I don't much like this option. I am not writingthe front end code,but I want to make it easy for the developer. Ideally, I would like to givehim a flattened viewso he can just do a simple join and run his report.I believe that what I want cannot be accomplished with ANSI SQL. However,does MS SQL have someextensions that could help me do the job? Failing that, how could I write astored procedure that wouldreturn the personID and the "Classes" string in a format that would bejoinable to the other tables?Thanks,Bill MacLeanP.S. Some people like to see actual database scripts as samples instead ofa textual representation.I have pasted in a script that creates sample tables and populates them.--Sample Tables and Reports:TABLE PERSONPersonID LastNM FirstNM--------- ----------- ---------1 Smith John2 Jones Sara3 Smith LucilleTABLE CLASSClassID ClassNM----------- ------------------10 SQL Server 10120 C++25 Object Oriented Design40 Inorganic Chemistry50 Organic Chemistry80 Early Lit.TABLE ENROLLMENTPersonID ClassID-------- ---------1 102 101 401 803 203 25SAMPLE REPORTPerson ID Name Classes--------- ----------------------- -----------------------------------------------------------------1 Smith, John SQL Server 101, Inorganic Chemistry,Early Lit.2 Jones, Sara SQL Server 1013 Smith, Lucille C++, Object Oriented Design/************************************************** ********SQL Server Script/************************************************** ********/CREATE TABLE [dbo].[CLASS] ([ClassID] [int] NOT NULL ,[ClassNM] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL) ON [PRIMARY]GOCREATE TABLE [dbo].[ENROLLMENT] ([PersonID] [int] NOT NULL ,[ClassID] [int] NOT NULL) ON [PRIMARY]GOCREATE TABLE [dbo].[PERSON] ([PersonID] [int] NOT NULL ,[LastNM] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,[FirstNM] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL) ON [PRIMARY]GOALTER TABLE [dbo].[CLASS] WITH NOCHECK ADDCONSTRAINT [PK_CLASS] PRIMARY KEY CLUSTERED([ClassID]) ON [PRIMARY]GOALTER TABLE [dbo].[ENROLLMENT] WITH NOCHECK ADDCONSTRAINT [PK_ENROLLMENT] PRIMARY KEY CLUSTERED([PersonID],[ClassID]) ON [PRIMARY]GOALTER TABLE [dbo].[PERSON] WITH NOCHECK ADDCONSTRAINT [PK_PERSON] PRIMARY KEY CLUSTERED([PersonID]) ON [PRIMARY]GOALTER TABLE [dbo].[ENROLLMENT] ADDCONSTRAINT [FK_ENROLLMENT_CLASS] FOREIGN KEY([ClassID]) REFERENCES [dbo].[CLASS] ([ClassID]),CONSTRAINT [FK_ENROLLMENT_PERSON] FOREIGN KEY([PersonID]) REFERENCES [dbo].[PERSON] ([PersonID])GO-- Insert rwo for each CLASSINSERT INTO CLASS VALUES (10,'SQL Server 101');INSERT INTO CLASS VALUES (20,'C++');INSERT INTO CLASS VALUES (25,'Object Oriented Design');INSERT INTO CLASS VALUES (40,'Inorganic Chemistry');INSERT INTO CLASS VALUES (50,'Organic Chemistry');INSERT INTO CLASS VALUES (80,'Early Lit.');-- Insert row for each PERSONINSERT INTO PERSON VALUES (1, 'Smitn','John');INSERT INTO PERSON VALUES (2, 'Jones','Sara');INSERT INTO PERSON VALUES (3, 'Smith','Lucille');--Insert row for each ENROLLMENTINSERT INTO ENROLLMENT VALUES (1,10);INSERT INTO ENROLLMENT VALUES (1,40);INSERT INTO ENROLLMENT VALUES (1,80);INSERT INTO ENROLLMENT VALUES (2,10);INSERT INTO ENROLLMENT VALUES (3,20);INSERT INTO ENROLLMENT VALUES (3,25);

View 3 Replies View Related

Excel Export Problem - Flattened Recursive Hierarchy

Feb 1, 2008

Hi,

I have a recursive hierarchy in SSRS2005 which contains accounts like so:

+ Revenue
+ Expense

which is grouped using details group and can be expanded like:

+ Revenue
- Revenue type
- Revenue type
- etc.
+ Expense
- Expense type
- Expense type
- etc.

It can be drilled down in five levels. This works fine in both SSAS and SSRS, but when I export the report to excel 2003, the hierarchy gets flattened, meaning that every account on the detail level (level 5) is exposed. Not what I had in mind. Rather SSRS should create a hierarchy in excel as well..

Is there a workaround for this?

View 3 Replies View Related

Declare A Concatenated Value.

May 5, 2008

OMG i'm so stupid, i edited my original post instead of replying!!

I was wondering if there was away to write a stored procedure where I concatenate several columns to create a Phrase and use that Phrase as a new value to do a second search in another table.

Example.

Table 1.

Column1 (Modem) Column2 (Highspeed) Column3 (Black)

Concatenated to be MODEM HIGHSPEED BLACK.

The 2nd table has the concatenated value as it's own column and 2nd column for the number in Inventory.

Column1 (MODEM HIGHSPEED BLACK) Column2 (44)

View 7 Replies View Related

Removing Rows That Contains Long String

Mar 23, 2004

Anyone know how to check the length of a varchar data in a table? I want to delete rows that contains an entry that exceeds 100 characters.

I should be able to write a program to do it, but I am wondering if I can do it in SQL.

View 2 Replies View Related

Split String And Insert Into Rows

Apr 4, 2014

I have a string stored in field v_images in table tbl_DealerFeed_temp. This string is split by the "|" character. I want to create a SQL query to grab this string, split it, and insert it into tbl_Vehicles_photos. I also need to pass the value d_id into the photos table:

tbl_Vehicles_photos:
vp_id, d_id, vp_image_name

The vp_id is the unique ID. I need to populate the d_id and vp_image_name field with my values.

View 1 Replies View Related

Converting String Into Rows Query?

Sep 19, 2014

I have a string like below

DECLARE @STR VARCHAR(100) = 'AAAAAA~KKKKK~LLLL~AAAA'

i want to convert the string into rows like

AAAAAA
KKKKK
LLLL
AAAA

View 2 Replies View Related

Problem Converting Rows To A String

Jul 23, 2005

I try to accomplish the following:I have two tables which are connected via a third table (N:Nrelationship):Table 1 "Locations"LocationID (Primary Key)Table 2 "Specialists"SpecialistID (Primary Key)Name (varchar)Table 3 "SpecialistLocations"SpecialistID (Foreign Key)LocationID (Foreign Key)(both together are the primary key for this table)Issuing the following commandSELECTL.LocationID , S.[Name]FROMLocations AS LLEFT JOIN SpecialistLocations AS SL ON P.PlaceID = SL.LocationIDLEFT JOIN Specialists AS S ON SL.SpecialistID = S.SpecialistIDresults in the following table:LocationID | Name1Specialist 11Specialist 22Specialist 32Specialist 43Specialist 14Specialist 4Now my problem: I would like to have the following output:LocationID | Names1Specialist 1, Specialist 22Specialist 3, Specialist 43Specialist 14Specialist 4....which is grouping by LocationID and concatenating the specialistnames.Any idea on how to do this?Thank you very much,Dennis

View 5 Replies View Related

Concatenated Results In A Batch SP

Aug 20, 2007

I've got a system that's grown like Topsy over the years and is now being asked to do things it was never designed for. As such I'm having to attempt ever more workarounds.

In a simple 3 column table

tbl1
(

SSN char(9),
reason varchar(50),
group char(1)
)

I have a batched stored proc that selects rows based on the SSN



select reason, group
from tbl
where group = 'I' AND ssn = @ssn;


select reason, group
from tbl
where group = 'C' AND ssn = @ssn;


select reason, group
from tbl
where group = 'N' AND ssn = @ssn;


Now they want to group the rows and I'd really like to know beforehand how many and which groups to expect. So, I need to add a 4th batch select to the top of the statement that would return a up to 3 char string that indicates which groups are following. Something like IN or IC or CN, etc.

This should be a trivial query but I can't figure it out.

Thanks.

View 7 Replies View Related

Two Strings To Be Concatenated Have Different Collation.

Mar 27, 2007

I'm using SQL Datatype SqlString, so I'm not sure what is going wrong...any help?
Here is a shortened version of the issue: Code and then Full Error Message.

Thanks in advance for any help


VB CODE




Code Snippet

Partial Public Class StoredProcedures
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub MyProc(ByVal cAddress1 As SqlString, ByVal cCity As SqlString, ByRef sName As SqlString)
Dim output As SqlString
Dim space As New SqlString(" ")
output = System.Data.SqlTypes.SqlString.Concat(cAddress1, space)
sName = output
End Sub
End Class
Error Message

Msg 6522, Level 16, State 1, Procedure MyProc Line 0
A .NET Framework error occurred during execution of user defined routine or aggregate 'MyProc':
System.Data.SqlTypes.SqlTypeException: Two strings to be concatenated have different collation.
System.Data.SqlTypes.SqlTypeException:
at System.Data.SqlTypes.SqlString.op_Addition(SqlString x, SqlString y)
at System.Data.SqlTypes.SqlString.Concat(SqlString x, SqlString y)
at SqlServerProject1.StoredProcedures.MyProc(SqlString cAddress1, SqlString cCity)

View 1 Replies View Related

Creating An SQL Connection String And Inserting New Rows.

Jun 15, 2006

I am ultra new to this so thanks in advance for any help.
I was trying to create a connection to a database that I created in SQL Express. I am essentially trying to submit three attributes to the existing database from a table that consists of three textboxes and a submit button. I would like all of the code to be in the head of the page (because that is the standard here) so I wanted to know what the connection string should be in Visual Basic 2005 Express to establish a connection on the same machine. I'm not sure about the connection string, but I am also not sure about a lot of the code. Also, the Using clauses seem to give me an error (where should it go?). This is what I have in the head of the page (visual C# by the way). Also, I got this from http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson03.aspx :
Using System.Data;Using System.Data.SqlClient;protected void Button1_Click(object sender, EventArgs e){SqlConnection conn = new SqlConnection("Data Source=(local);Database=CustomersDB;Trusted Connection=true");conn.Open();string insertstring = @" insert into Catagories (CustomerID, CustomerName, CustomerEmail) values (" + textbox1.value + ", " + textbox2.value + " + ", textbox3.value");SqlCommand cmd = new SqlCommand(insertstring, conn);Sql.ExecuteNonQuery();conn.close();}
If there is absolutely any insite into the problems with my code, I really appreciate it.

View 12 Replies View Related

Multiple Rows Into A Comma Delimited String

May 22, 2007

I have the following table:id name1 yes2 no3 what4 is5 this6 niceThe amount of rows can vary from 1 to 50. I only need the name column.What SQL statement do I have to execute to get the following:yes,no,what,is,this,nice,  (trailing , is acceptable)Thanks!

View 1 Replies View Related

Return Multiple Rows Into One Single String

Nov 1, 2005

Hi,

I need to return multiple rows into one single string

Declare @String varchar(1000)

Create table Cus (CusId Int,CusName varchar(10))

Insert into Cus Select 1,'John'
Union All
Select 2,'Bob'

Select * from Cus returns

1John
2 Bob

I need to return the all the rows from Cus table into a single string. The return is dynamic.
I do not know the number of rows returned

My result should be

@String = 1,John,2,Bob

How can i do that ?

View 2 Replies View Related

Split String And Insert Into Table Rows

Apr 17, 2014

I have a string which is delimited by commas:

Green,Red,Blue,Orange,Black,White

I need to create a SQL statement to read the string, split it at the "," character, and insert it into individual rows. I also need to insert an ID (the same for all split values).

For instance:

INSERT INTO tbl_Temp (unique_id, ID, color) VALUES (1, 999, Green)
INSERT INTO tbl_Temp (unique_id, ID, color) VALUES (2, 999, Red)
INSERT INTO tbl_Temp (unique_id, ID, color) VALUES (3, 999, Blue)
etc...

I would like to be able to do this all in one statement so I don't have to break it out into individual SQL statements.

View 4 Replies View Related

How To Return Value From Multiple Rows In A Single String

Oct 7, 2007



I have a table having Style Nos (VarChar Col), how I can return values from multiple rows in a single string.

for Example if table is having 3 records :-

1. Style 1
2. Style 2
3. Style 3

It should return single value in this way

Style 1, Style 2, Style 3


View 10 Replies View Related

Concatinating String Values From Multiple Rows

Nov 4, 2006

I currently have some SQL code that is used to build a string that is a concatination of string values across multiple rows.  The subqueries in the script sometimes return NULL values so I use the following statement to change the default behavior of the concatination operator which prevents my query from returning NULL:

SET CONCAT_NULL_YIELDS_NULL ON

Here's the code snippet:

select DISTINCT

(SELECT CASE WHEN (t1.MaskValue & HDR.TranTypeID)=1 THEN ' ' + t1.description ELSE '' END FROM transactiontypes t1 WHERE (t1.MaskValue & HDR.TranTypeID)=1) +

(SELECT CASE WHEN (t2.MaskValue & HDR.TranTypeID)=2 THEN ' ' + t2.description ELSE '' END FROM transactiontypes t2 WHERE (t2.MaskValue & HDR.TranTypeID)=2) +

(SELECT CASE WHEN (t3.MaskValue & HDR.TranTypeID)=4 THEN ' ' + t3.description ELSE '' END FROM transactiontypes t3 WHERE (t3.MaskValue & HDR.TranTypeID)=4) +

(SELECT CASE WHEN (t4.MaskValue & HDR.TranTypeID)=8 THEN ' ' + t4.description ELSE '' END FROM transactiontypes t4 WHERE (t4.MaskValue & HDR.TranTypeID)=8) +

(SELECT CASE WHEN (t5.MaskValue & HDR.TranTypeID)=16 THEN ' ' + t5.description ELSE '' END FROM transactiontypes t5 WHERE (t5.MaskValue & HDR.TranTypeID)=16)) as 'Transaction Type'

FROM HDResponse HDR

Here's the underlying table structure:
CREATE TABLE [dbo].[TransactionTypes](
             [ID] [int] IDENTITY(1,1) NOT NULL,
             [Description] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,        [MaskValue] [int] NOT NULL) ON [PRIMARY]
CREATE TABLE [dbo].[HDResponse](
             [ResponseID] [int] IDENTITY(1,1) NOT NULL,
             [LoggedDateTime] [datetime] NULL,
             [ResponseTypeTripID] [int] NULL,
             [ResponseTypeID] [int] NULL,
             [ResponseTypeObjectID] [int] NULL,
             [ObjectID] [int] NULL,
             [IDHolderID] [int] NULL,
             [TransportCode] [int] NULL,
             [CardID] [int] NULL,
             [IssueCode] [smallint] NULL,
             [EventDateTime] [datetime] NULL,
             [Response] [bit] NULL,
             [TranTypeID] [int] NULL)
             ON [PRIMARY]

The problem I am having is I need to be able to use the query above in a view used for reporting.  Unfortunately, you cannot use SET CONCAT_NULL_YIELDS_NULL ON in a view.  This causes my query to return NULL if any of the subqueries return NULL.  I could create a function to do something similar and reference the function in the query but I can't help but think there must be a way to get this done in a single query.

Any thoughts or ideas would be greatly appreciated.

Thanks!!!!!

View 1 Replies View Related

How To Put New Data Into SqlDataSource Update With Concatenated Key?

Jan 26, 2006

Here is the problem.
I have table such as this
PK selection VARCHARPK selection_choice VARCHAR      show BIT
When I use the sqlDataSource to create an update it creates this.UPDATE lu_selection_choices SET show = @show WHERE (selection = @selection) AND (selection_choice = @selection_choice)
Now this is OK, but when you perform an update and in say a details control you change the selection_choice the value of the parameter @selection_choice is going to be equal to the old data.  So it performs a successful update on show which isn't being changed selection_choice is.
So the questions is.  Is there anyway to tell the update function of the datasource to insert the a new parameter with the SET selection_choice = @SOME NEW PARAM slection_choice?
Thanks,
Darren King
 

View 4 Replies View Related

How To Extract Data From A Concatenated Field

Sep 28, 2006

Hi everyone. I need help extracting information from a concatenated field delimited by a '/' character. I know that the logic is to basically find the position of the '/' character and use the substring function to extract the data but I am unfamiliar with how to do this in SQL Server 2000. Please see examples below. Thanks in advance.


FIELD
----------
1234/4567
2345/6754
1234


I need to extract the data before and after the '/' character. There are records however with on the leftmost part of the data such as row number 3.

FIELD 1 FIELD 2
------------------
1234 4567
2345 6754
1234

View 3 Replies View Related

Concatenated Column Returns Null

Mar 7, 2008

Hi folks,I have an issue with a column I created in my query called Instance.SELECT Object_Id, Event_type, Audience, Subject, Provider, Academic_Year, Start_date, End_date, CONVERT(varchar, Academic_Year) + ' (' + CONVERT(varchar, Start_date, 103) + ') : ' + Event_type AS InstanceFROM EventsORDER BY Event_type Above is my query. The problem is because the start date column can be null, it also returns the Instance column as null for that row.I thought it would have just missed out the date and display the rest, but it doesn't.Is there any way I could get the Instance column to display a value, when the start date is null?ThanksEdit: Managed to sort it using ISNULL()

View 14 Replies View Related

Null Field On Concatenated Code

Jan 28, 2014

I have a concated code from excel when I have to pick some values for db update, the problem is when one field is empty, this field is date type and I don't now how can I validate if UserDate_02 field is null or not, I get it from a cell in excel and later when I get all the code I update the db, this is the line :

UPDATE ITEMS SET UserField_01='AA',UserDate_01='01/28/2014',UserYesNo_01=1,UserDate_02=''WHERE LotNumber='134034143017297'and ItemCode='G22221'

View 2 Replies View Related

Change Format Of Concatenated Columns

Mar 23, 2008

Is there a way to have my output return this, "$-2,778.90 $$$ IN NETWORK DISCOUNT", instead of what I am currently getting which is this "-2779 $$$ IN NETWORK DISCOUNT" using:

LTRIM(STR(ar_billtrans_payadj.amount)+ ' ' + '$$$' + ' ' + ut_journalcode.[description]) AS PPmtTypeDesc

ar_billtrans_payadj.amount datatype is decimal
ut_journalcod.[description] datatype is varchar

View 5 Replies View Related

Search On Concatenated Fields In Sql Server

Sep 21, 2005

Greetings,I used to do this kind of query in Ingres, where I concatenate(+)various fields as one field and search accordingly.Is there an equivalent method in SQL server ?SELECT a.rsrcid,a.rsrchqnumber,c.perslastname,c.persfirst name,b.asgtid,b.asgtactualstartdate,b.asgtactualenddate ,CASE b.enumstateWHEN '2' THEN 'Running'WHEN '3' THEN 'Cancelled'WHEN '4' THEN 'Closed'WHEN '6' THEN 'Open'END AS statusFROM pblocal.dbo.resources aINNER JOIN pblocal.dbo.assignments b ON b.asgtrsrcguid = a.rsrcguidINNER JOIN pblocal.dbo.persons c ON c.persguid = a.rsrcpersguidWHERE a.rsrcid+a.rsrchqnumber+c.perslastname+c.persfirst name not in(SELECT e.rsrcid+e.rsrchqnumber+g.perslastname+g.persfirst nameFROM dtlocal.dbo.resources eINNER JOIN dtlocal.dbo.assignments f ON f.asgtrsrcguid = e.rsrcguidINNER JOIN dtlocal.dbo.users h ON h.userguid = e.rsrcuserguidINNER JOIN dtlocal.dbo.persons g ON g.persguid = h.userpersguid)

View 6 Replies View Related

MAX Doesn't Apply For Concatenated Variables?

Mar 28, 2006

If I load up a local variable defined as varchar(MAX) with a 10,000-character continuous string, i.e. '123456789.....100000' the variable retains the full value as expected. However, if I break that string up into '123456789....5000' + '5001...10000', the variable is truncated at 8000 characters.

Is there a way around this?

Thanks.

View 1 Replies View Related







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