Hi,
I want to get position of "(" within the string, and do not know what @p0 is 0.
Declare @str as varchar;
declare @p0 decimal(12,0)
select @str='MNO ()';
set @p0 =CHARINDEX('(',@str);
select @p0
--select substring(@str,1,@p0-1) as res
go
Hi,
I want to get position of "(" within the string, and do not know what @p0 is 0.
Declare @str as varchar;
declare @p0 decimal(12,0)
select @str='MNO ()';
set @p0 =CHARINDEX('(',@str);
select @p0
--select substring(@str,1,@p0-1) as res
go
When you declare a varchar (or any other datatype that can have a length like char, nvarchar, binary, etc), you want to always specify a length. If you don't, you will get a default length. In the case you have the default length of @str is 1. So the value put into @str is just the first character or 'M'. So @str does not have a '(' in it, so the result of the CHARINDEX is 0.
Tom
15 people are following this question.
Year and Month aggregation in same Pivot table in SQL Server
SQL Server Query for Searching by word in a string with word breakers
How to show first row group by part id and compliance type based on priorities of Document type?
Query to list all the databases that have a specific user
T-sql query to find the biggest table in a database with a clustered index