I have a table with total no of 1000 records in it.It has the following structure: I want to calculate no of records for every month in year-2012 Is there any way that should solve my issue in a single shot? I tried: Answer
Tag: sql-server-2008
How to make a list of T-SQL results with comma’s between them?
Suppose we have a simple query like this: If we have one record in the result set, I want to set variable @v to that one value. If we have two or more records, I’d like the results to be separated by a comma and a space. What is the best way to write this T-SQL code? Example: result set
Getting max value from rows and joining to another table
Sorry if this is being stupid, I am really a newbie trying to nail this. Table A: ID Rank Name 1 100 Name1 1 45 Name2 2 60 Name3 2 42 Name4 2 88 Name5 Table B: ID FileName 1 fn1 …
Issues using sqlsrv_rows_affected, it keeps returning false even when its true
I have a query that changes a users password, and I want to check the users knows their current password before being able to change it. So it is working, I need to enter the current password before changes will be made, but my outputs are still always false, here is the code I have: Can anyone see this won’t
Creating text file without using bcp in sql
I have to query a table and print the output in a text file. I have a normal user login with dbo permission on the database. I cannot use bcp or cannot give any special permissions. Can anyone help me with this? Answer You can’t create a text file on the server or elsewhere with only permissions in the database.
insert into values with where clause
I am trying to programmatically enter values into my table. I cannot use a straight Select @variables. I have to use the keyword Values. How can I create a where clause when using Values in the insert into. I am trying to avoid duplicates Answer
Split time records across midnight
I’m trying to run some reports and having to deal with the whole issue of employee labor hours crossing midnight. It occurs to me though that I could split the records that cross midnight into two records as if the employee clocked out at midnight and simultaneously clocked back in at midnight thus avoiding the midnight problem altogether. So if
Changing the maximum length of a varchar column?
I’m trying to update the length of a varchar column from 255 characters to 500 without losing the contents. I’ve dropped and re-created tables before but I’ve never been exposed to the alter statement which is what I believe I need to use to do this. I found the documentation here: ALTER TABLE (Transfact-SQL) however I can’t make heads or
Showing what quarter of a financial year a date is in
I’m trying to construct a query that will map two columns, one, a date from a table, the second column an alias to show what quarter and financial year the date falls into. Unfortunately I don’t have enough knowledge of SQL to know where to begin. I know that I’d do this with a combination of getdate() and dateadd(MONTH,,) however
Set variable value to array of strings
I want to set a variable as a string of values. E.g. declare @FirstName char(100) select @FirstName = ‘John’,’Sarah’,’George’ SELECT * FROM Accounts WHERE FirstName in (@FirstName) I’m getting a …