Showing posts with label line. Show all posts
Showing posts with label line. Show all posts

Monday, March 19, 2012

Getting records in a line (commalist)

Hi,

i searched for many hours now and I need help from the community ;)

I have a list of records and want to include the records as a comma sperated list in an other select statement.

I tried it with std. SQL and later with T-SQL, and I am sure it will work ith a stored procedure, but I am not that professional in this (try to learn...).

Background: I have a lot of data (users) and want to create a records set without having the data processed in my scripts.

So i have: records in table krgroupusers (example data):

lgroupid, luserid
3 , 1
3 , 48
4 , 1
197 , 1
197 , 48
197 , 250
197 , 251
207 , 1

207 , 250

Weiter habe ich eine Tabelle kruser (example data):

lid, strusername , strmail
1 , Administrator , admin@.test.de
48 , user1 , user1@.test.de
250, user2 , user2@.test.de
251, user3 , user3@.test.de

A StoredP. or SQL query should give me the following result:

lid, strusername , strmail , sgroups (example data):

1 , Administrator , admin@.test.de , 3,4,197,207
48 , user1 , user1@.test.de , 3,197
250, user2 , user2@.test.de , 197,207
251, user3 , user3@.test.de , 197

So I am happy for any help...

hi Yves,

please refer to this post

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

regards

|||

Hi,

Thx alot that helps me to do it.

One final question ;) Is it possible to do this with a virtual table ?! or do i have to create a table and drop it again.

I not familiar with this but i read some things about @.@.table...

Friday, February 24, 2012

Getting error while using "text" datatype

Hello, I am writing a sproc and am getting this error: Any ideas? Thanks!!

Msg 402, Level 16, State 1, Procedure InsertUserPreferences, Line 18

The data types text and text are incompatible in the equal to operator.

-

create procedure InsertUserPreferences

(

@.PublisherServer text

)

as

begin

if exists(Select Preference_StringList from USER_Preference where Preference_StringList = @.PublisherServer)

begin

--UPDATE

exec dbo.uProc_USER_Preference

end

If you are using 2005, change to using varchar(max) and this will work. You cannot use a text value in a equality comparison

create table test
(
textValue text
)
go
select *
from test
where textValue = ''
go

You could use a cast to only get the first 8000 characters:

select *
from test
where cast(textValue as varchar(8000)) = ''
go

If that will work for you.

Is that your entire proc? How des the update work? If it exists, do you just update the modify date?

|||I will give it a shot and get back with you. Thank you for your help!!!|||Dude that worked!! Thanks man!!!!

Getting error while using "text" datatype

Hello, I am writing a sproc and am getting this error: Any ideas? Thanks!!

Msg 402, Level 16, State 1, Procedure InsertUserPreferences, Line 18

The data types text and text are incompatible in the equal to operator.

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

create procedure InsertUserPreferences

(

@.PublisherServer text

)

as

begin


if exists(Select Preference_StringList from USER_Preference where Preference_StringList = @.PublisherServer)

begin

--UPDATE

exec dbo.uProc_USER_Preference

end

You cannot use an equal operator with TEXT or NTEXT. You can only use LIKE for comparison. Why are you using text, and not varchar? Are you using SQL 2000 or 2005?|||

Hello and thanks for responding!! I restored data from a SQL Server 2000 database to a SQL Server 2005 to meet our requirements. It was our DBA's decision to make that field a datatype of 'text'.

|||I would recommend changing it to VARCHAR if possible.