Tweet's xml format - tweetsharp

I get ' top tweets ' from twitter as an RSS feed in xml format .
There is a guid field in that xml format.
There is a long 11 digit number at the end of guid field , is it unique for every tweet ?

GUID stands for Globally Unique Identifier, so yes.

Related

How to select a numeric part of nvarchar datatype field

I want to select the numeric part of data that saved in nvarchar() datatype column in sqlserver.
The size of a character in rows doesn't same and maybe some of the rows don't have the numeric part on the column, for example, the data format like
/TablePhoneHome>
or
<TablePhoneHome></TablePhoneHome>
or
<TablePhoneHome><Number Num="9123159834"/></TablePhoneHome>
or
<TablePhoneHome><Number Num="somthing"/></TablePhoneHome>
I want to select the phone number from that like :
09151826166-09151150374
null
9123159834
Assuming the data type is actually xml (and if it isn't, then you should fix your data type to be xml) you can easily use XQUERY to get the value:
SELECT YT.YourColumn.value('(/TablePhoneHome/Number/#Num)[1]','varchar(50)') AS Num
FROM YourTable YT;

convert one column to json

Using Azure SQLServer I'm trying to convert only one column to json format. The data is in a nvarchar field. Using For Json Auto will convert all fields and all rows. What I need is just to convert only one column.
By converting to json what I mean is to be clickable to see it's data a new window inside SSMS.
Let's say the table (Logs) has 2 columns: LogId and LogData. LogData is nvarchar(max) and contains json data.
What I need is to query the table and have a clickable logData column.
You can try like following to get only one column as JSON
select o.*,
(select YourColumnForJson
from YourTable i
where o.Identifer=i.Identifer for json auto) as JsonColumn
from YourTable o

Return rows where ID is in semicolon separated string from subquery MSSQL

I'm trying to query my sql database to return all the rows where the ID is contained in a separate tables column. The list of project IDs is kept in the Feedback table in the Project_ID Column with datatype varchar. I am trying to return the rows from the Projects table where the IDs are kept in the Project_ID column with datatype varchar.
I am doing this using the query
SELECT * FROM Projects WHERE Project_ID IN (
SELECT Project_ID FROM Feedback WHERE ID = 268 and Project_ID IS NOT NULL
)
When I run this query I am returned with the message:
Conversion failed when converting the varchar value '36;10;59' to data type int
This is yet another example of the importance of normalizing your data.
Keeping multiple data points in a single column is almost never the correct design, and by almost never I mean about 99.9999%.
If you can't normalize your database, you can use a workaround like this:
SELECT *
FROM Projects p
WHERE EXISTS (
SELECT Project_ID
FROM Feedback F WHERE ID = 268
AND Project_ID IS NOT NULL
AND ';'+ F.Project_ID +';' LIKE '%;'+ CAST(p.Project_ID as varchar) +';%'
)
You can't use the IN operator since it's expecting a list of values delimited by a comma, while you try to supply it with a single value that is delimited by a semicolon. Even if the values in Project_ID was delimited by a comma it would still not work.
The reason I've added the ; on each side of the Project_ID in both tables is that this way the LIKE operator will return true for any location it finds the Projects.Project_Id inside the Feedback.Project_Id. You must add the ; to the Projects.Project_Id to prevent the LIKE to return true when you are looking for a number that is a partial match to the numbers in the delimited string. Consider looking for 12 in a string containing 1;112;455 - without adding the delimiter to the search value (12 in this example) the LIKE operator would return true.

How to search from varchar column with - on it

I am trying to search from SQL table where my column where to search is varchar type and my keyword for the search should be imported from Excel, like this:
SELECT table.column FROM table WHERE column="for example"42-3
So, the column consists varchar type variables formed with few numbers then "-" and then one number. To Excel I write for example 42-3 and macro should find every row with 42-3 from that table.
I think somehow I should convert it or take it apart when I could only search by numbers but I don't know how to do that when there is - in the variable.
EDIT:
so, in my SQL table I have a first column where are varchar variables 42-1,42-1,42-2,45-1,46-1... second column I have numbers 1,5,11,3,1,6,2... third column I have amounts 300,52 , 200,10 , 712,31 , 0,44... I should make a search with WHERE command for for example WHERE column1=42-1
I can write this "42-1" straight from excel as string format so that is not a problem, only that the character type is in varchar format and consists - so I can not convert it to integer.
Try using '%' operator
Select * from tableName where column1 like value1+'%'

how to fix arabic characters saved in my table

i need your help in this as i am stuck .
i have 2 tables the collation of some fields is arabic ( address , client Name ) bith these fields collation are arabic .
table one ( uploaded_data ) fields -----> client_name , client_address
i use upload excel file to table1 ( uploaded_data) and its succesfully work 100% and the address and name coming in arabic
means there is no problems in this table
i add trigger on insert for table 1 to save data in table 2 by using
select * from insrted
table two ( client_Files ) fields ------>client_name , client_address
the problem that when the trigger fired and the data saved to table 2 the records not showing known characters its coming rabish because i use the parameter to save the data
if i use the field direct without using the parameter its working fine
so can any one advice and note taht all fields name and address are arabic collation
please advice
Check if your column type is NVARCHAR instead of Varchar .Because NVARCHAR supports unicode.

Resources