Skip to content

Tag: sql

Get DateTime with time as 23:59:59

I’m trying to do a where statement that specifies a DateTime field is between the start and end of the previous month. To do this, I need to specify that the first day of the previous month has a time of 00:00:00 and the last day of the previous month has a time of 23:59:59. This second condition is giv…

Update Query with select and row lock

I got this query as part of a previous answer to my question. Now how to lock the rows in the select query to make sure no other thread over writes my update. Answer It’s not clear to me that you have the problem you seem to think you have. Updating a row in the table inherently places a row-level

How to query database by id using SqlAlchemy?

I need to query a SQLAlchemy database by its id something similar to but for id. How do I do this? [Searching over Google and SO didn’t help] Answer Query has a get function that supports querying by the primary key of the table, which I assume that id is. For example, to query for an object with ID of

Numbers of weekdays in a date range in TSQL

This is harder than it looks. I need a function that calculates the numbers of a given weekday in a date range. I don’t want any loops or recursive SQL. There are millions of examples doing just that. I need a fast function for calculation. Input of the function will be weekday, fromdata, todate Expecte…

How to write query for this?

Hi friends I have a table like this ID bid sub_bid cid sub_cid 1 0 2 1 0 2 5 0 3 0 3 3 0 0 4 4 2 0 4 0 on that table either (bid or sub_bid) OR (cid or sub_cid) will be null. I have to write a query for fetching like this.. if bid is