sql

Accept Multiple Data Types in Stored Procedure

I'll avoid any explanations and just get to the question. Is there a way to accept multiple data types for one parameter of a MySQL stored procedure? I want to be able to accept both int and varchar-typed data for an IN parameter of the procedure. Is this possible? I know this is not good practice (I'd never choose to do it myself) but...

MySql to Sql Server migration questions

I did a succesful migration from MySql to Sql Server using the migration tool. Unfortunately for some reason it labels the tables database.DBO.tablename instead of just database.tablename I have never used Sql Server so perhaps this is just the way they name their tables. When I do: SELECT TOP 1000 [rid] ,[filename] ,[qc...

sql-server which owner should i use?

i have about 10 scientists writing to a mysql database i have migrated to sql server and now i have to deal with OWNERS does it matter which owner i choose? when i do automate migration frmo mysql to sql server it assigns DBO. is that OK? should i continue to use that? so now i have to do: SELECT TOP 1000 [rid] ,[filename] ...

How can I get only one row per record in master table?

Hi guys, it is possible to get only one row per record in a multitable query? I have this three tables: APPLES ID | APPLE ---------- 1 | RED 2 | YELLOW 3 | GREEN FARMS ID | FARM -------------------- B1 | GEORGE'S FARM B2 | JOHN'S FARM FARM_APPLES FARM | APPLE --------------- B1 | 1 B1 | 2 B1 | 3 B2 | 1 B3 |...

LINQ to Entities Join on DateTime.DayOfWeek

Imagine two tables: Shifts, RANK_S_DAY. Shifts contains a ShiftDate column which is DateTime and RANK_S_DAY has a DayOfWeek column. I need to join (int)ShiftDate.DayOfWeek equals DayOfWeek. I understand why it won't work, but I'm not quite sure how I can change it. The Exception is: The specified type member 'DayOfWeek' is not su...

MySQL record existence optimization

Using a site like StackOverflow as an example: I have a table of users, questions, and user-questions mappings. My user-questions mappings table looks like this: userID (int 8) questionID (int 8) When displaying a list of popular questions, I am trying to mark the questions that have been posed by the logged-in user. Is it more effic...

How do I configure SQL to be a "shared hosting provider" for use within the Database Publishing Wizard?

VS2010 has the ability to either create a script, or "publish to shared hosting provider". What do I need to do to be able to use my private SQL server to become a Shared Hosting Provider for my dev team? What are the benefits of using this versus using traditional SQL scripts? ...

How can I optimise this query in MYSQL? What needs to be done

Please scroll down to the "25/08/2010 Update". I have a query which I have turned into a view. It runs very slowly because (as far as I understand) there are several issues with indexes on the joined tables. explain select * from view_ed_abc_print As you can see, I have table "a" using where, temporary and filesort with 4659 ro...

Syntax Difference in Table Alter/Add with and without a NULL

I have a question, but let me first say that this is being performed on a database which I inherited and I am currently trying to improve the design on. Also the reason for the syntax is the fact that there are a lot of tables that the datatypes have been 'tweaked' by tech support people (/facepalm) causing lots of issues. IF NOT EXISTS...

looping through a rails data object from the controller

I have called a function from a class to find all the items related to a particular ID in a many to many HABTM relationship. Procedures -> Tasks with a join table: procedures_tasks I call the information like @example = Procedure.get_tasks(1,1) I would like to be able to iterate through the data returned so that I can create an i...

when i run the query in query analyzer it returns one row but when i use the same query in vb.net no rows are returned

here is the code Function getData(ByVal id As String) Dim reader As SqlClient.SqlDataReader Dim statement As String Dim count As Integer Dim temp As Integer statement = "SELECT * FROM General WHERE accountid='" + id + "'" Conn.Open() Comm = New SqlClient.SqlCommand(statement, Conn) reader = Comm.Execute...

Sql string manipulation within stored procedure

Hi, I have a field which contains article titles. I need to create friendly or pretty url's out of the article titles. I need help manipulating the string with SQL. This has to be done within a stored procedure or function. The requirements: The only characters allowed are lowercase letters and numbers (a-z and 0-9) All spaces need to...

Trouble with contradicting where clause

Hi, I am trying to display what each user has spend their time doing for the week(either internal or external work) but the time is all on the same column on the table, is it possible to split it into 2 different columns and still have it so that it only shows each user once not each time they entered time which could be multiple times ...

SQL Query to Re-build Indexes

Hi Is there any SQL query equivalent to Re-building the indexes. In SQL Server Management Studio Select desired DB and select the table, click on the "+" symbol to expand the table properties, in that select indexes, if already indexes exists it will list. Right click the index you can see "Rebuild " option What i want is the this op...

question on Group by clause in Sql server

Table: Customer Name Type Amount James P 125.00 James P 125.00 James P 125.00 James R 225.00 James R 225.00 Rajiv R 155.00 Rajiv R 155.00 Rajiv R 155.00 Rajiv P 150.00 Rajiv P 150.00 Saran R 175.00 In this table structure I want a output which will give each person’s count of P, count...

systable for sql server

Is there any system table to find the columns for DDLChangeLog_ID, InsertionDate,CurrentUser, LoginName, Username, EventType, objectName, objectType, tsql ...

SQL 2008 Express (R2): Creating an UPDATE trigger to update a table on another server?

Hi there, I am just trying to think through a process I need where I have: One SQL 2008 express database on a webserver - takes orders into an orders table Another SQL 2008 express database on another webserver acting as a backend system to process the orders etc The idea being that the webserver database can be left to do what it d...

How can I do SELECT UNIQUE with LINQ?

I have a list like this: Red Red Brown Yellow Green Green Brown Red Orange I am trying to do a SELECT UNIQUE with LINQ, i.e. I want Red Brown Yellow Green Orange var uniqueColors = from dbo in database.MainTable where dbo.Property == true select dbo.Color.Name; I then changed this to var uniqueColors = from dbo in database.Ma...

cache repository's result or maybe sql server does it for me

I have repositories like this in my application public class FooRepo { public Foo Get(int id) { return Foo from Db; } } I'm just wondering if there is possible to do some caching for the methods inside the repository, or probably there is no need because sql-server does it for me, but if needed could someone point/s...

Column not found error with simple SQL query

I know its almost there, but base is telling me it can't find a column called table1.id when I know its there! UPDATE table2 SET col1 = (SELECT field1 FROM table1 WHERE table2.id = table1.id) WHERE table1.id = table2.id ...