Hi, SQL expert, I have a question to consult you.
We have a table with fields to conbine user first name, last name and company name, and other information. There are two fields related, propertynames, propertyvalues. The two columns are ntext data type.
Some data sample like:
propertynames: FirstName:S:0:7:LastName:S:7:5:CompanyName:S:12:5:
propertyvalues: JeffreyMcGeeIntel
I need to add a filter for compnay name.
So my SQL code is:
substring(propertyvalues, Cast(substring(substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)),1, CHARINDEX(':',substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)))-1) as int)+1,
cast(substring(substring(substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)), CHARINDEX(':',substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)))+1, DATALENGTH(propertynames)),1, CHARINDEX(':',substring(substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)), CHARINDEX(':',substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)))+1, DATALENGTH(propertynames)))-1) as int))
It is successfully like all company name. But when I add a filter to get company = 'Intel' I got error:"Conversion failed when converting the nvarchar value 'Name' to data type int." I am not sure what proble is. Please help me to solve the problem.
Thanks a lot for any help.
Jeanne
We have a table with fields to conbine user first name, last name and company name, and other information. There are two fields related, propertynames, propertyvalues. The two columns are ntext data type.
Some data sample like:
propertynames: FirstName:S:0:7:LastName:S:7:5:CompanyName:S:12:5:
propertyvalues: JeffreyMcGeeIntel
I need to add a filter for compnay name.
So my SQL code is:
substring(propertyvalues, Cast(substring(substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)),1, CHARINDEX(':',substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)))-1) as int)+1,
cast(substring(substring(substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)), CHARINDEX(':',substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)))+1, DATALENGTH(propertynames)),1, CHARINDEX(':',substring(substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)), CHARINDEX(':',substring(propertynames, CHARINDEX('companyname', propertynames)+len('companyname:s:'), DATALENGTH(propertynames)))+1, DATALENGTH(propertynames)))-1) as int))
It is successfully like all company name. But when I add a filter to get company = 'Intel' I got error:"Conversion failed when converting the nvarchar value 'Name' to data type int." I am not sure what proble is. Please help me to solve the problem.
Thanks a lot for any help.
Jeanne