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
 Help need with string separation

Author  Topic 

reacha
Starting Member

49 Posts

Posted - 2010-10-11 : 12:05:43
i have a query like this

select @res = select top(1) (CONVERT(varchar(30), eventid, 113))+''+ '@'+''+ convert(varchar(30),AUDIT.Auditstamp,113) from audit
where AUDIT.pkgid = 9288283
and AUDIT.audittype = 7
and queueid <> -1
order by AUDIT.auditstamp desc

The output of this query is

31@23 Aug 2010 18:58:38:307

Now i need to separate the result

as getting the value before @ into one variable
and after the @ value into another variable


Please help me out!!

Thanks,
reacha

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-10-11 : 12:14:07
[code]select top 1 @res = (CONVERT(varchar(30), eventid, 113)),
@otherVar = convert(varchar(30),AUDIT.Auditstamp,113)
from audit
where AUDIT.pkgid = 9288283
and AUDIT.audittype = 7
and queueid <> -1
order by
AUDIT.auditstamp desc
[/code]

actually, don't need to convert 'em since no need to concatenate this way
Go to Top of Page

reacha
Starting Member

49 Posts

Posted - 2010-10-11 : 12:20:57
Select @AuditstampQueueEntered = select top(1)(AUDIT.auditstamp),
@QueueEventID= (dbo.AUDIT.eventid )
from audit
where AUDIT.pkgid = @pkgid
and AUDIT.audittype = 7
and queueid <> -1
order by AUDIT.auditstamp desc)

I am getting the error message as
Msg 156, Level 15, State 1, Procedure msp_EventIDAuditStampQueueEntered, Line 15
Incorrect syntax near the keyword 'select'.
Msg 141, Level 15, State 1, Procedure msp_EventIDAuditStampQueueEntered, Line 15
A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-11 : 12:29:23
[code]Select top 1 @AuditstampQueueEntered = AUDIT.auditstamp,
@QueueEventID= dbo.AUDIT.eventid
from audit
where AUDIT.pkgid = @pkgid
and AUDIT.audittype = 7
and queueid <> -1
order by AUDIT.auditstamp desc
[/code]

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

Go to Top of Page
   

- Advertisement -