Please take a close look at that and describe what is different between it and the query you're running. If that doesn't work for you (please try it in TempDB or in some other database), then you're either looking at the wrong table, or you're misinterpreting the data.Īnd here we go, a working SQLfiddle example. To get blank datatable you can do like this: you can do it as: SELECT NewsItem FROM NewsTable IF ROWCOUNT > 0 BEGIN SELECT 'No Data' AS NewsItem END Let me know if it helps you in any way. This works fine for me, so something must be different for you (was trying to demonstrate using SQLfiddle but the SQL Server component is currently down): Hi, When there is no data returned by the query, then you will get blank datatable on Application. Is your connection string using AttachDbFileName by any chance? If this is the case then it's possible that in Visual Studio you see one copy of the database and in Management Studio or wherever you're running this query, you're looking at a different (empty) copy. If this is a date/time data type and not a string, and this query returns zero rows, then either you don't have any data from 2003, or you are running against the wrong copy of the database. or, for result sets that should return multiple rows, you could use the columnCount method: sql 'SELECT p2gtext FROM p2g' result pdo->query (sql) if (result->columnCount (). Maciejs solution will work, but it means effectively running the query twice, which is both inefficient and risks problems if the query needs to be modified. Doing it in SQL returns a variable number of columns, which is messy for presentation. <- and please have your instructor read this! Its simple there: retrieve the rows, count them, and take the appropriate action. I'm avoiding BETWEEN because, if Hire_Date is DATETIME, it is possible that someone could have been hired on December 31 at 8:00 AM, and this person would be left out of your BETWEEN clause. WHERE e.Hire_Date >= '20030101'- this should be a filter (WHERE), not join criteria INNER JOIN dbo.Job_TitleT AS t - use proper, explicit JOINs instead of 1970s syntax The database is running on SQL Server 2016 SP2. For example, the following SQL query invokes a user-defined SQL function as a method. In case its relevant, both the Appointment.StudentUsername and User.Username columns are NVARCHAR(200). or, for result sets that should return multiple rows, you could use the columnCount method: sql SELECT p2gtext FROM p2g result pdo->query (sql) if (result->columnCount (). Assuming Hire_Date is DATETIME you should do this: SELECT e.LastName, e.HireDate - properly denote which table a column comes fromįROM dbo.EmployeeT AS e - use schema prefix and use meaningful aliases How can the same query return no results unless I happen to copy the value for the WHERE clause from the results of another query on the same table P.S.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |