I’m trying to generate a random time between 8:00 AM and 8:00 PM for each row that is selected from a data set, however, I always get the same random value for each row – I want it to be different for each row. Table schema & data: Сurrent SQL statement: Current results (same time for each row in the
Tag: sql-server-2008
‘MOD’ is not a recognized built-in function name
I wanted to use MOD function in SQL Server 2008R2 and followed this link but still got the message: ‘MOD’ is not a recognized built-in function name. Error: Msg 195, Level 15, State 10, Line 2 ‘MOD’ is not a recognized built-in function name. Why I can’t use this function from the link above? Answer The MOD keyword only exists
Query database tables for missing link
I have two tables in my database and they each share the a field called cID. So here’s an example: Parent Table _______________ cID Name — —— 1 Record #1 2 Record #2 3 Record #3 …
SQL Query – Incorrect syntax near the keyword ‘LIKE’
The following query is giving an error at ‘CASE WHEN NOT LIKE’ (Msg 156, Level 15, State 1, Line 14 Incorrect syntax near the keyword ‘LIKE’) SELECT TimeStamp, TimeStampNS, ISNULL(TagName, ‘…
How to convert a varchar column to bit column in SQL SERVER
Flag1 is a varchar column with values “true” and “false”. I need to convert this into bit column. When I try to do this: Convert(Bit,Flag1) it shows an error Msg 245, Level 16, State 1, Line 2 …
How to replace first and last character of column in sql server?
I have a database column and its give a string like ,Recovery, Pump Exchange,. I want remove first and last comma from string. Expected Result : Recovery, Pump Exchange. Answer You can use SUBSTRING for that: Obviously, an even better approach would be not to put leading and trailing commas there in the first place, if this is an option.
Database does not exist. Make sure that the name is entered correctly
Why am I having this error? If you looked at the screenshot, you will see the database. It only happens when I am connected to two database engines. It only detects the databases from database engine …
SQL Server : round and add percent sign
I have the following SQL query that is returning a result of 92.967013425802 and I need it to be formatted like 93% and add the percent sign. I have tried changing the sum to round but I received an …
T-SQL split string based on delimiter
I have some data that I would like to split based on a delimiter that may or may not exist. Example data: John/Smith Jane/Doe Steve Bob/Johnson I am using the following code to split this data into …
How to find last weekday of current month using SQL
How would I calculate the last weekday of the current month given a date using SQL? I was able to get the last day of current month, but not sure how to do the last weekday programmatically. I don’t want to generate a calendar look-up table. Here’s the last day of month code i’m currently using: Answer I know it