|
sorry but i am a beginner , i do not know how to start exactly
i have just my sql request which is correct and works well
|
|
|
|
|
i'm used to MySQL, this is...different. A table with just one row
Using "DB Browser for SQLLite"...structure
CREATE TABLE "appinfo" (
"version" TEXT NOT NULL,
"passworded" INTEGER NOT NULL,
"username" TEXT NOT NULL
);
I added a row. "1", 1, "Admin" with DB Browser
when I query it "SELECT * FROM addinfo;" with DB browser I get NULL for each field (blank on my c# app)
what am I missing here?
thanks
|
|
|
|
|
Uranium-235 wrote: what am I missing here? The correct spelling of "appinfo".
|
|
|
|
|
no, that wasn't a copy & paste, it was a misspelling here, when I actually do it from my c# app it returns the column names (found a function to easily present col names and row data, so the columns are correct), and one row of empty data, just like in DB Browser
I just tried SELECT * FROM "main"."appinfo";
it returned <blank>, 0, <blank>
the middle number is supposed to be a 1
modified 12-Apr-20 14:39pm.
|
|
|
|
|
I'm having trouble parsing your query! I would presume that "Main" is your database and is included in your connection string.
If so then your query string should be "Select * from appinfo" and it should return the 1 record you have inserted.
If you want an empty datatable then "Select * from Appinfo where 1=1"
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
no this is from DB Browser, not even the app
|
|
|
|
|
Nevermind. I inserted it into the database with a query in DB Browser instead of using the browser and it seemed to work :shrug:
thanks for putting up with me
|
|
|
|
|
Whatever you think you entered perhaps did not happen. Or your query is somehow incorrect. You can easily get all the information from SQLite database files using the sqlite3 command line interface.
|
|
|
|
|
Just out the blue today I started getting this error on my Dev PC.
Cannot open database "MyDb" requested by the login. The login failed.
Login failed for user 'MicrosoftAccount\my_ms_account'.
The account name is one of my Microsoft account names, and happens to be the one tied this PC's Windows 10. There IS NO SQL login with that name. There have been no DB structure changes. Today I've done typical CRUD operations via C# & Linq-To-SQL. And again, this just started this afternoon.
I Googled it and found this. I'm hesitant to try that fix until I know what's happening. For now, if I log off and back on it seems to fix it, but then I have to close and reopen everything.
Anyone know what this is?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Do you normally connect from an elevated process? If so, the BUILTIN\Administrators login would apply, and you wouldn't need a separate login for your account. But if you then tried to connect from a non-elevated process, you wouldn't be part of the Administrators group.
The SQL setup normally has a step where it adds the current user to the sysadmin role so that you don't have to elevate to connect. Was SQL installed by a different user, or did you prevent it from adding your user account?
Have you switched from a local account to a Microsoft account recently?
Did the restart fix it permanently, or did the problem come back?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Do you normally connect from an elevated process?
I used Trusted Connection
Richard Deeming wrote: Was SQL installed by a different user, or did you prevent it from adding your user account?
No
Richard Deeming wrote: Have you switched from a local account to a Microsoft account recently?
No
Richard Deeming wrote: Did the restart fix it permanently, or did the problem come back?
It reoccurs
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Well, I just noticed that my database was in Singlr User Mode. I set it back to Multi User and the problem no longer seems to appear.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Is there a way to split data into two separate tables with a single SQL statement? I know that sounds like an odd question, but I have a large table in terms of rows, and I would like to "split" the data into two separate tables for separate processing in parallel fashion. Call me crazy but I thought there was a way to do that in SQL Server, i.e. a SQL statement to divide the table into two separate tables.
Is there a way to do that or am I misremembering?
|
|
|
|
|
Take a look at partitioning although I would be wary of physically splitting a table simply for parallel processing, there are probably better ways of doing the job.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Just run two selects ("in one statement"). Select "top half" (count / 2) in one case, select the rest for the other (not in; greater than; whichever).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Why not implement it in a procedure?
|
|
|
|
|
Hello:
I need help with this:
SELECT *
FROM
(SELECT
CASE
WHEN InvoiceMonth IN (1,2,3) THEN 1
WHEN InvoiceMonth IN (4,5,6) THEN 2
WHEN InvoiceMonth IN (7,8,9) THEN 3
WHEN InvoiceMonth IN (10,11,12) THEN 4
END as Quarter
FROM viewSalesTracker_Model1
WHERE Quarter = @Quarter
The error I am receiving is:
Error Source: .Net SqlClient Data Provider
Error Message: Must declare the scalar variable "@Quarter".
|
|
|
|
|
It means that the compiler does not know what @Quarter is. You have not declared it anywhere.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Michele Smith wrote: Error Source: .Net SqlClient Data Provider
Error Message: Must declare the scalar variable "@Quarter".
Then declare this "@Quarter"variable!
|
|
|
|
|
Once you've declared the @Quarter variable or parameter, you'll run into another error:
Invalid column name 'Quarter'.
You can't reference an alias introduced in the SELECT clause within the WHERE clause of the same statement. You either have to use a sub-query, a common table expression, or duplicate the logic of the alias in the WHERE clause.
SELECT Quarter
FROM
(
SELECT CASE
WHEN InvoiceMonth IN (1,2,3) THEN 1
WHEN InvoiceMonth IN (4,5,6) THEN 2
WHEN InvoiceMonth IN (7,8,9) THEN 3
WHEN InvoiceMonth IN (10,11,12) THEN 4
END As Quarter
FROM viewSalesTracker_Model1
)
WHERE Quarter = @Quarter; Or:
WITH cteQuarters As
(
SELECT CASE
WHEN InvoiceMonth IN (1,2,3) THEN 1
WHEN InvoiceMonth IN (4,5,6) THEN 2
WHEN InvoiceMonth IN (7,8,9) THEN 3
WHEN InvoiceMonth IN (10,11,12) THEN 4
END As Quarter
FROM viewSalesTracker_Model1
)
SELECT Quarter
FROM cteQuarters
WHERE Quarter = @Quarter; Or:
SELECT CASE
WHEN InvoiceMonth IN (1,2,3) THEN 1
WHEN InvoiceMonth IN (4,5,6) THEN 2
WHEN InvoiceMonth IN (7,8,9) THEN 3
WHEN InvoiceMonth IN (10,11,12) THEN 4
END As Quarter
FROM viewSalesTracker_Model1
WHERE CASE
WHEN InvoiceMonth IN (1,2,3) THEN 1
WHEN InvoiceMonth IN (4,5,6) THEN 2
WHEN InvoiceMonth IN (7,8,9) THEN 3
WHEN InvoiceMonth IN (10,11,12) THEN 4
END = @Quarter;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I cannot figure out why my trigger keeps inserting duplicates. Do anyone see what might might be causing it.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[update_ee_so_email]
ON [dbo].[import_new_soemailsubmission]
AFTER INSERT , UPDATE, Delete
AS
BEGIN
Declare @new_agentId as uniqueidentifier --varchar(10)
Declare @new_email as varchar(50)
Declare @agentid as varchar(10)
Select @agentid = SO.new_agentId, @new_email = new_email
FROM inserted SE join import_new_serviceorganization SO ON SE.new_agentId = SO.ID
join app_users a on a.user_name = 'SO-' + SO.new_agentid
IF @agentid is not null
Begin
INSERT INTO EE_SO_MAILING_LISTS ([PARTNER], EMAIL_ADDRESS,STATEMENT_FLAG, REFRESH_DATE)
Values(@agentid, @new_email, 'N', GetDate())
END
Else if exists (Select * from deleted)
Begin
Select @new_agentId = new_agentId, @new_email = new_email
FROM deleted
Select @agentid =new_agentId From import_new_serviceorganization Where id = @new_agentId
Delete from EE_SO_MAILING_LISTS where PARTNER = @agentid and EMAIL_ADDRESS = @new_email
End
END
|
|
|
|
|
You can't treat triggers like this. Triggers will often have multiple records in the inserted and deleted tables so you can't use variables.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
How are you suppose to do them?
|
|
|
|
|
Depends on what you were trying to do but using variables will never work when there’s more than one record in the inserted or deleted tables.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
As well as the issue of multiple affected records, your trigger is trying to handle all three DML operations (INSERT , UPDATE , and DELETE ). But the code only seems to be handling the INSERT and DELETE cases.
- For
INSERT , there will be records in the inserted virtual table, but none in the deleted virtual table; - For
DELETE , there will records in deleted , but none in inserted ; - For
UPDATE , there will be records in both;
Use the inserted and deleted Tables - SQL Server | Microsoft Docs[^]
It would almost certainly be simpler to have separate queries for each operation. Try something like this:
CREATE OR ALTER TRIGGER [dbo].[insert_ee_so_email]
ON [dbo].[import_new_soemailsubmission]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO dbo.EE_SO_MAILING_LISTS
(
[PARTNER],
EMAIL_ADDRESS,
STATEMENT_FLAG,
REFRESH_DATE
)
SELECT
SO.new_agentId,
I.new_email,
'N',
GetDate()
FROM
inserted As I
INNER JOIN dbo.import_new_serviceorganization As SO
ON SO.ID = I.new_agentId
WHERE
Exists
(
SELECT 1
FROM dbo.app_users As A
WHERE A.user_name = 'SO-' + SO.new_agentId
)
;
END
GO
CREATE OR ALTER TRIGGER [dbo].[update_ee_so_email]
ON [dbo].[import_new_soemailsubmission]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
If Updated(new_email)
BEGIN
UPDATE
L
SET
EMAIL_ADDRESS = I.new_email
FROM
dbo.import_new_serviceorganization As SO
INNER JOIN inserted As I
ON I.new_agentId = SO.ID
INNER JOIN deleted As D
ON D.new_agentId = SO.ID
INNER JOIN dbo.EE_SO_MAILING_LISTS As L
ON L.PARTNER = SO.new_agentId
And L.EMAIL_ADDRESS = D.new_email
;
END;
END
GO
CREATE OR ALTER TRIGGER [dbo].[delete_ee_so_email]
ON [dbo].[import_new_soemailsubmission]
AFTER DELETE
AS
BEGIN
SET NOCOUNT ON;
DELETE
FROM
L
FROM
dbo.EE_SO_MAILING_LISTS As L
WHERE
Exists
(
SELECT 1
FROM dbo.import_new_serviceorganization As SO
INNER JOIN deleted As D
ON D.new_agentId = SO.ID
WHERE SO.new_agentId = L.PARTNER
And D.new_email = L.EMAIL_ADDRESS
)
;
END
GO
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|