Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Max Length of text field

Author  Topic 

gnaus
Starting Member

41 Posts

Posted - 2011-09-21 : 05:54:46
dear reader,

I want to know from field "OpmerkingenIndicatie" at which record it has the most characters or the most Kb.

My formula works so far, but I want that he shows me at which Clientcode (=field) this occurs. I don't know how to do this.
this is my formula:

SELECT ' OpmerkingenIndicatie,'
(SELECT MAX(DATALENGTH(OpmerkingenIndicatie))


FROM dbo.Oefenomgeving$OpmerkingenIndicatie2)

or
SELECT ' OpmerkingenIndicatie,' ' Clientcode '

(SELECT MAX(DATALENGTH(OpmerkingenIndicatie))


FROM dbo.Oefenomgeving$OpmerkingenIndicatie2)


but in both cases he tells me wich field is the biggest but he doesn't tell me at which clientcode that is.

thank you,




GN

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 05:57:01
[code]SELECT OpmerkingenIndicatie,Clientcode
FROM Table
WHERE DATALENGTH(OpmerkingenIndicatie)=
(SELECT MAX(DATALENGTH(OpmerkingenIndicatie) FROM table)
[/code]



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gnaus
Starting Member

41 Posts

Posted - 2011-09-22 : 04:03:09
thank you!

result:

SELECT OpmerkingenIndicatie,Clientcode
FROM dbo.Oefenomgeving$OpmerkingenIndicatie2
WHERE DATALENGTH(OpmerkingenIndicatie)=
(SELECT MAX(DATALENGTH(OpmerkingenIndicatie) FROM dbo.Oefenomgeving$OpmerkingenIndicatie2)

Foutmelding: Msg 156, Level 15, State 1, Line 13
Incorrect syntax near the keyword 'FROM'.

next try-out:

SELECT OpmerkingenIndicatie,Clientcode
FROM dbo.Oefenomgeving$OpmerkingenIndicatie2
WHERE DATALENGTH(OpmerkingenIndicatie)=
MAX(DATALENGTH(OpmerkingenIndicatie))


Msg 147, Level 15, State 1, Line 10
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

greetings, GN

GN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-22 : 04:08:34
[code]SELECT OpmerkingenIndicatie,Clientcode
FROM dbo.Oefenomgeving$OpmerkingenIndicatie2
WHERE DATALENGTH(OpmerkingenIndicatie)=
(SELECT MAX(DATALENGTH(OpmerkingenIndicatie)) FROM dbo.Oefenomgeving$OpmerkingenIndicatie2)
[/code]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gnaus
Starting Member

41 Posts

Posted - 2011-09-22 : 05:15:43
super! it works!
thanks!! :)


GN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-22 : 11:43:06
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -